Sha256: 5e68860528448ff9ccd72d0cffd62e171c6adbe17fee1ee30e5581791c4c6bfb

Contents?: true

Size: 1.26 KB

Versions: 48

Compression:

Stored size: 1.26 KB

Contents

module Flipper
  module UI
    module Util
      # Private: 0x3000: fullwidth whitespace
      NON_WHITESPACE_REGEXP = /[^\s#{[0x3000].pack("U")}]/

      def self.blank?(str)
        str.to_s !~ NON_WHITESPACE_REGEXP
      end

      def self.present?(str)
        !blank?(str)
      end

      def self.titleize(str)
        str.to_s.split('_').map(&:capitalize).join(' ')
      end

      def self.truncate(str, length: 30)
        if str.length > length
          str[0..length]
        else
          str
        end
      end

      def self.pluralize(count, singular, plural)
        if count == 1
          "#{count} #{singular}"
        else
          "#{count} #{plural}"
        end
      end

      def self.to_sentence(array, options = {})
        default_connectors = {
          words_connector: ", ",
          two_words_connector: " and ",
          last_word_connector: ", and "
        }
        options = default_connectors.merge!(options)

        case array.length
        when 0
          ""
        when 1
          "#{array[0]}"
        when 2
          "#{array[0]}#{options[:two_words_connector]}#{array[1]}"
        else
          "#{array[0...-1].join(options[:words_connector])}#{options[:last_word_connector]}#{array[-1]}"
        end
      end
    end
  end
end

Version data entries

48 entries across 48 versions & 1 rubygems

Version Path
flipper-ui-0.26.0.rc2 lib/flipper/ui/util.rb
flipper-ui-0.26.0.rc1 lib/flipper/ui/util.rb
flipper-ui-0.25.4 lib/flipper/ui/util.rb
flipper-ui-0.25.3 lib/flipper/ui/util.rb
flipper-ui-0.25.2 lib/flipper/ui/util.rb
flipper-ui-0.25.1 lib/flipper/ui/util.rb
flipper-ui-0.25.0 lib/flipper/ui/util.rb
flipper-ui-0.24.1 lib/flipper/ui/util.rb
flipper-ui-0.24.0 lib/flipper/ui/util.rb
flipper-ui-0.23.1 lib/flipper/ui/util.rb
flipper-ui-0.23.0 lib/flipper/ui/util.rb
flipper-ui-0.22.2 lib/flipper/ui/util.rb
flipper-ui-0.22.1 lib/flipper/ui/util.rb
flipper-ui-0.22.0 lib/flipper/ui/util.rb
flipper-ui-0.21.0 lib/flipper/ui/util.rb
flipper-ui-0.21.0.rc2 lib/flipper/ui/util.rb
flipper-ui-0.21.0.rc1 lib/flipper/ui/util.rb
flipper-ui-0.20.4 lib/flipper/ui/util.rb
flipper-ui-0.20.3 lib/flipper/ui/util.rb
flipper-ui-0.20.2 lib/flipper/ui/util.rb