Class: String

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

Instance Method Summary collapse

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

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:



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

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:



35
36
37
38
# File 'lib/volt/extra_core/string.rb', line 35

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

#titleizeObject



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

def titleize
  self.gsub('_', ' ').split(' ').map {|w| w.capitalize }.join(' ')
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