Module: CoreExt::String

Defined in:
lib/core_ext/string.rb

Constant Summary collapse

FALSE_VALUES =

Adapted from active_model/types/boolean rubocop:disable Lint/BooleanSymbol

[
  false, 0,
  "0", :"0",
  "f", :f,
  "F", :F,
  "false", :false,
  "FALSE", :FALSE,
  "off", :off,
  "OFF", :OFF,
].freeze
LENGTH =

Maximum number of characters displayed

75

Instance Method Summary collapse

Instance Method Details

#as_hObject



26
27
28
# File 'lib/core_ext/string.rb', line 26

def as_h
  self
end

#as_sObject



30
31
32
# File 'lib/core_ext/string.rb', line 30

def as_s
  "\"#{chomp.tr("\n", ' ').truncate(LENGTH)}\""
end

#to_bObject



22
23
24
# File 'lib/core_ext/string.rb', line 22

def to_b
  self == "" ? nil : FALSE_VALUES.exclude?(self)
end