class String
Public Instance Methods
remove_underscores()
click to toggle source
# File lib/quantify/core_extensions/string.rb, line 12 def remove_underscores self.gsub("_"," ") end
starts_with_number?()
click to toggle source
# 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?()
click to toggle source
# 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_quantity()
click to toggle source
# File lib/quantify/core_extensions/string.rb, line 38 def to_quantity Quantify::Quantity.parse(self) end
Also aliased as: to_q
with_superscript_characters()
click to toggle source
# File lib/quantify/core_extensions/string.rb, line 4 def with_superscript_characters self.gsub(/\^2\b/,"²").gsub(/\^3\b/,"³") end
without_superscript_characters()
click to toggle source
# File lib/quantify/core_extensions/string.rb, line 8 def without_superscript_characters self.gsub(/¹\b/,"").gsub(/²\b/,"^2").gsub(/³\b/,"^3") end
word_count()
click to toggle source
# File lib/quantify/core_extensions/string.rb, line 20 def word_count words.size end
words()
click to toggle source
# File lib/quantify/core_extensions/string.rb, line 16 def words split(/\s+/) end