Class: String
- Defined in:
- lib/volt/extra_core/blank.rb,
lib/volt/extra_core/string.rb
Instance Method Summary collapse
-
#blank? ⇒ Boolean
A string is blank if it’s empty or contains whitespaces only:.
-
#camelize ⇒ Object
TODO: replace with better implementations NOTE: strings are currently immutable in Opal, so no ! methods.
- #dasherize ⇒ Object
- #plural? ⇒ Boolean
- #pluralize ⇒ Object
- #singular? ⇒ Boolean
- #singularize ⇒ Object
- #titleize ⇒ Object
- #underscore ⇒ Object
Instance Method Details
#blank? ⇒ Boolean
A string is blank if it’s empty or contains whitespaces only:
''.blank? # => true
' '.blank? # => true
' '.blank? # => true
' something here '.blank? # => false
73 74 75 76 77 |
# File 'lib/volt/extra_core/blank.rb', line 73 def blank? # self !~ /[^[:space:]]/ # TODO: Opal fails with the previous regex self.strip == '' end |
#camelize ⇒ Object
TODO: replace with better implementations NOTE: strings are currently immutable in Opal, so no ! methods
6 7 8 |
# File 'lib/volt/extra_core/string.rb', line 6 def camelize self.split("_").map {|s| s.capitalize }.join("") end |
#dasherize ⇒ Object
14 15 16 |
# File 'lib/volt/extra_core/string.rb', line 14 def dasherize self.gsub('_', '-') end |
#plural? ⇒ Boolean
30 31 32 33 |
# File 'lib/volt/extra_core/string.rb', line 30 def plural? # TODO: Temp implementation self.pluralize == self end |
#pluralize ⇒ Object
18 19 20 |
# File 'lib/volt/extra_core/string.rb', line 18 def pluralize Inflector.pluralize(self) end |
#singular? ⇒ Boolean
35 36 37 38 |
# File 'lib/volt/extra_core/string.rb', line 35 def singular? # TODO: Temp implementation self.singularize == self end |
#singularize ⇒ Object
22 23 24 |
# File 'lib/volt/extra_core/string.rb', line 22 def singularize Inflector.singularize(self) end |
#titleize ⇒ Object
26 27 28 |
# File 'lib/volt/extra_core/string.rb', line 26 def titleize self.gsub('_', ' ').split(' ').map {|w| w.capitalize }.join(' ') end |
#underscore ⇒ Object
10 11 12 |
# File 'lib/volt/extra_core/string.rb', line 10 def underscore self.scan(/[A-Z][a-z]*/).join("_").downcase end |