class Pug::NumberParser

Parses numeric values from text

Public Instance Methods

number_from_text(text) click to toggle source

Extracts number from text if it starts with a number @param text [String] text to extract number from @return [Integer, nil] number from text or nil

# File lib/pug/number_parser.rb, line 17
def number_from_text(text)
  return nil unless starts_with_numeric_text?(text)
  text.to_i
end
starts_with_numeric_text?(text) click to toggle source

Indicates if a text starts with a number @param text [String] text to test @return [Boolean] if text starts with numeric text

# File lib/pug/number_parser.rb, line 9
def starts_with_numeric_text?(text)
  text.to_i.positive? || text.strip.start_with?('0')
end