class String
Additional String
functionality
Constants
- BLANK_RE
Public Instance Methods
blank?()
click to toggle source
@return [true, false]
# File lib/marfa/helpers/classes/string.rb, line 55 def blank? empty? || BLANK_RE.match?(self) end
present?()
click to toggle source
Object
isn't blank @return [true, false]
# File lib/marfa/helpers/classes/string.rb, line 61 def present? !blank? end
to_class_name()
click to toggle source
Convert string like 'category/list' to CamelCase @example
"some/path".to_class_name
@return [String] changed string
# File lib/marfa/helpers/classes/string.rb, line 17 def to_class_name parts = downcase.split('/') parts.each(&:capitalize!) parts.join('').gsub(%r{-}, '') end
to_price!()
click to toggle source
Convert string price to preferred view @example
"1042.42".to_price!
@return [String]
# File lib/marfa/helpers/classes/string.rb, line 46 def to_price! # self.split('.') divides string into substring with '.' delimiter and returning array of this substrings # .first returns the first element of the array # .reverse returns a new string with the characters from str in reverse order # .gsub(pattern, replacement) returns a copy of str with the all occurrences of pattern substituted for the second argument self.split('.').first.reverse.gsub(/...(?=.)/, '\&;psniht&').reverse end
to_underscore()
click to toggle source
Replaces all '/' to '_' @example
"some/path".to_underscore
@return [String] changed string
# File lib/marfa/helpers/classes/string.rb, line 9 def to_underscore downcase.gsub(%r{/}, '_') end
to_url()
click to toggle source
Convert string to url part @example
"some/path".to_url
@return [String] changed string
# File lib/marfa/helpers/classes/string.rb, line 27 def to_url val = self.strip_tags! val = val.gsub(/[ —_\/]/, '-')#TODO: длинный пробел не работает val = val.gsub(/[+.,!?@#$%^&*()\[\]{}:;\/\\|<>"']/, '') #TODO: больше символов! val.downcase end