Class: String

Inherits:
Object show all
Defined in:
lib/volt/extra_core/blank.rb,
lib/volt/extra_core/string.rb,
lib/volt/reactive/string_extensions.rb

Instance Method Summary collapse

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_concatObject



6
# File 'lib/volt/reactive/string_extensions.rb', line 6

alias :__old_concat :<<

#__old_plusObject

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

Returns:



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

#camelizeObject

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

#dasherizeObject



14
15
16
# File 'lib/volt/extra_core/string.rb', line 14

def dasherize
  self.gsub('_', '-')
end

#plural?Boolean

Returns:



26
27
28
29
# File 'lib/volt/extra_core/string.rb', line 26

def plural?
  # TODO: Temp implementation
  self.pluralize == self
end

#pluralizeObject



18
19
20
# File 'lib/volt/extra_core/string.rb', line 18

def pluralize
  Inflector.pluralize(self)
end

#singular?Boolean

Returns:



31
32
33
34
# File 'lib/volt/extra_core/string.rb', line 31

def singular?
  # TODO: Temp implementation
  self.singularize == self
end

#singularizeObject



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

def singularize
  Inflector.singularize(self)
end

#underscoreObject



10
11
12
# File 'lib/volt/extra_core/string.rb', line 10

def underscore
  self.scan(/[A-Z][a-z]*/).join("_").downcase
end