Class: String
- Defined in:
- lib/volt/extra_core/blank.rb,
lib/volt/extra_core/string.rb,
lib/volt/reactive/string_extensions.rb
Instance Method Summary collapse
-
#+(val) ⇒ Object
In volt, we want a value + reactive strings to return a reactive string.
- #<<(val) ⇒ Object
- #__old_concat ⇒ Object
-
#__old_plus ⇒ Object
include ReactiveTags.
-
#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
- #underscore ⇒ Object
Instance Method Details
#+(val) ⇒ Object
In volt, we want a value + reactive strings to return a reactive string. So we over-ride + to check for when we are adding a reactive string to a string.
12 13 14 15 16 17 18 19 |
# File 'lib/volt/reactive/string_extensions.rb', line 12 def +(val) result = __old_plus(val.cur) if val.reactive? && !result.reactive? result = ReactiveValue.new(result) end return result end |
#<<(val) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/volt/reactive/string_extensions.rb', line 22 def <<(val) if val.reactive? raise "Cannot append a reactive string to non-reactive string. Use + instead" end result = __old_concat(val) return result end |
#__old_concat ⇒ Object
6 |
# File 'lib/volt/reactive/string_extensions.rb', line 6 alias :__old_concat :<< |
#__old_plus ⇒ Object
include ReactiveTags
4 |
# File 'lib/volt/reactive/string_extensions.rb', line 4 alias :__old_plus :+ |
#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
26 27 28 29 |
# File 'lib/volt/extra_core/string.rb', line 26 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
31 32 33 34 |
# File 'lib/volt/extra_core/string.rb', line 31 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 |
#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 |