Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/quantify/core_extensions/string.rb

Instance Method Summary collapse

Instance Method Details

#remove_underscoresObject



12
13
14
# File 'lib/quantify/core_extensions/string.rb', line 12

def remove_underscores
  self.gsub("_"," ")
end

#starts_with_number?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/quantify/core_extensions/string.rb', line 24

def starts_with_number?
  (/\A#{Unit::NUMBER_REGEX}/i).match(self) ? true : false
end

#starts_with_valid_unit_term?Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
34
35
36
# File 'lib/quantify/core_extensions/string.rb', line 28

def starts_with_valid_unit_term?
  return false unless 
  term = /\A#{Unit.unit_label_regex}#{Unit::INDEX_REGEX}?/.match(self) || 
         /\A#{Unit.unit_symbol_regex}#{Unit::INDEX_REGEX}?/.match(self) || 
         /\A#{Unit.unit_name_regex}#{Unit::INDEX_REGEX}?/.match(self)  || 
         /\A#{Unit::UNIT_DENOMINATOR_REGEX}/.match(self) || 
         /\A(#{Unit::UNIT_PREFIX_TERMS_REGEX}|#{Unit::UNIT_SUFFIX_TERMS_REGEX})/i.match(self) 
  return term[0]
end

#to_quantityObject Also known as: to_q



38
39
40
# File 'lib/quantify/core_extensions/string.rb', line 38

def to_quantity
  Quantify::Quantity.parse(self)
end

#with_superscript_charactersObject



4
5
6
# File 'lib/quantify/core_extensions/string.rb', line 4

def with_superscript_characters
  self.gsub(/\^2\b/,"²").gsub(/\^3\b/,"³")
end

#without_superscript_charactersObject



8
9
10
# File 'lib/quantify/core_extensions/string.rb', line 8

def without_superscript_characters
  self.gsub(/¹\b/,"").gsub(/²\b/,"^2").gsub(/³\b/,"^3")
end

#word_countObject



20
21
22
# File 'lib/quantify/core_extensions/string.rb', line 20

def word_count
  words.size
end

#wordsObject



16
17
18
# File 'lib/quantify/core_extensions/string.rb', line 16

def words
  split(/\s+/)
end