module Flipper::UI::Util
Constants
- NON_WHITESPACE_REGEXP
Private: 0x3000: fullwidth whitespace
Public Class Methods
blank?(str)
click to toggle source
# File lib/flipper/ui/util.rb, line 7 def self.blank?(str) str.to_s !~ NON_WHITESPACE_REGEXP end
pluralize(count, singular, plural)
click to toggle source
# File lib/flipper/ui/util.rb, line 27 def self.pluralize(count, singular, plural) if count == 1 "#{count} #{singular}" else "#{count} #{plural}" end end
present?(str)
click to toggle source
# File lib/flipper/ui/util.rb, line 11 def self.present?(str) !blank?(str) end
titleize(str)
click to toggle source
# File lib/flipper/ui/util.rb, line 15 def self.titleize(str) str.to_s.split('_').map(&:capitalize).join(' ') end
to_sentence(array, options = {})
click to toggle source
# File lib/flipper/ui/util.rb, line 35 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
truncate(str, length: 30)
click to toggle source
# File lib/flipper/ui/util.rb, line 19 def self.truncate(str, length: 30) if str.length > length str[0..length] else str end end