Class: NumberMuncher::Token::Base
- Inherits:
-
Object
- Object
- NumberMuncher::Token::Base
- Defined in:
- lib/number_muncher/token/base.rb
Instance Attribute Summary collapse
-
#text ⇒ Object
readonly
Returns the value of attribute text.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #float? ⇒ Boolean
- #fraction? ⇒ Boolean
-
#initialize(text, captures = nil) ⇒ Base
constructor
A new instance of Base.
- #inspect ⇒ Object
- #int? ⇒ Boolean
- #to_a ⇒ Object
Constructor Details
Instance Attribute Details
#text ⇒ Object (readonly)
Returns the value of attribute text.
4 5 6 |
# File 'lib/number_muncher/token/base.rb', line 4 def text @text end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
4 5 6 |
# File 'lib/number_muncher/token/base.rb', line 4 def value @value end |
Class Method Details
.captures(scanner, text) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/number_muncher/token/base.rb', line 11 def self.captures(scanner, text) if scanner.respond_to?(:captures) scanner.captures.map(&:presence) else match = regex.match(text) match.regexp.named_captures.each_with_object([]) do |(capture, _), arr| arr << match[capture] end end end |
.scan(scanner) ⇒ Object
7 8 9 |
# File 'lib/number_muncher/token/base.rb', line 7 def self.scan(scanner) new(scanner.matched, captures(scanner, scanner.matched)) if scanner.scan(regex) end |
Instance Method Details
#==(other) ⇒ Object
48 49 50 51 52 |
# File 'lib/number_muncher/token/base.rb', line 48 def ==(other) return to_a == other if other.is_a?(Array) super end |
#float? ⇒ Boolean
33 34 35 |
# File 'lib/number_muncher/token/base.rb', line 33 def float? false end |
#fraction? ⇒ Boolean
37 38 39 |
# File 'lib/number_muncher/token/base.rb', line 37 def fraction? false end |
#inspect ⇒ Object
54 55 56 |
# File 'lib/number_muncher/token/base.rb', line 54 def inspect to_a.to_s end |
#int? ⇒ Boolean
29 30 31 |
# File 'lib/number_muncher/token/base.rb', line 29 def int? false end |
#to_a ⇒ Object
41 42 43 44 45 46 |
# File 'lib/number_muncher/token/base.rb', line 41 def to_a [ self.class.name.demodulize.underscore.to_sym, value ] end |