class String
Public Instance Methods
blank?()
click to toggle source
A string is blank if it's empty or contains whitespaces only:
''.blank? # => true ' '.blank? # => true ' '.blank? # => true ' something here '.blank? # => false
# File lib/volt/extra_core/blank.rb, line 72 def blank? self !~ /\S/ end
camelize(first_letter = :upper)
click to toggle source
Turns a string into the camel case version. If it is already camel case, it should return the same string.
# File lib/volt/extra_core/string.rb, line 9 def camelize(first_letter = :upper) new_str = gsub(/[_\-][a-z]/) { |a| a[1].upcase } new_str = new_str[0].capitalize + new_str[1..-1] if first_letter == :upper new_str end
dasherize()
click to toggle source
# File lib/volt/extra_core/string.rb, line 22 def dasherize gsub('_', '-') end
headerize()
click to toggle source
# File lib/volt/extra_core/string.rb, line 38 def headerize split(/[_-]/) .map { |new_str| new_str[0].capitalize + new_str[1..-1] } .join('-') end
html_safe()
click to toggle source
# File lib/volt/page/bindings/html_safe/string_extension.rb, line 2 def html_safe # Convert to a real string (opal uses native strings normally, so wrap so we can # use instance variables) str = String.new(self) str.instance_variable_set('@html_safe', true) str end
html_safe?()
click to toggle source
# File lib/volt/page/bindings/html_safe/string_extension.rb, line 10 def html_safe? @html_safe end
plural?()
click to toggle source
# File lib/volt/extra_core/string.rb, line 44 def plural? # TODO: Temp implementation pluralize == self end
pluralize()
click to toggle source
# File lib/volt/extra_core/string.rb, line 26 def pluralize Volt::Inflector.pluralize(self) end
singular?()
click to toggle source
# File lib/volt/extra_core/string.rb, line 49 def singular? # TODO: Temp implementation singularize == self end
singularize()
click to toggle source
# File lib/volt/extra_core/string.rb, line 30 def singularize Volt::Inflector.singularize(self) end
titleize()
click to toggle source
# File lib/volt/extra_core/string.rb, line 34 def titleize gsub('_', ' ').split(' ').map(&:capitalize).join(' ') end
underscore()
click to toggle source
Returns the underscore version of a string. If it is already underscore, it should return the same string.
# File lib/volt/extra_core/string.rb, line 18 def underscore gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').gsub(/([a-z\d])([A-Z])/, '\1_\2').downcase end