Class: Pug::NumberParser

Inherits:
Object
  • Object
show all
Defined in:
lib/pug/number_parser.rb

Overview

Parses numeric values from text

Instance Method Summary collapse

Instance Method Details

#number_from_text(text) ⇒ Integer?

Extracts number from text if it starts with a number

Parameters:

  • text (String)

    text to extract number from

Returns:

  • (Integer, nil)

    number from text or nil



17
18
19
20
# 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) ⇒ Boolean

Indicates if a text starts with a number

Parameters:

  • text (String)

    text to test

Returns:

  • (Boolean)

    if text starts with numeric text



9
10
11
# File 'lib/pug/number_parser.rb', line 9

def starts_with_numeric_text?(text)
  text.to_i.positive? || text.strip.start_with?('0')
end