Class: Dentaku::Token
- Inherits:
-
Object
- Object
- Dentaku::Token
- Defined in:
- lib/dentaku/token.rb
Instance Attribute Summary collapse
-
#category ⇒ Object
readonly
Returns the value of attribute category.
-
#raw_value ⇒ Object
readonly
Returns the value of attribute raw_value.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #close? ⇒ Boolean
- #empty? ⇒ Boolean
- #grouping? ⇒ Boolean
-
#initialize(category, value, raw_value = nil) ⇒ Token
constructor
A new instance of Token.
- #is?(c) ⇒ Boolean
- #length ⇒ Object
- #open? ⇒ Boolean
- #operator? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(category, value, raw_value = nil) ⇒ Token
Returns a new instance of Token.
5 6 7 8 9 |
# File 'lib/dentaku/token.rb', line 5 def initialize(category, value, raw_value = nil) @category = category @value = value @raw_value = raw_value end |
Instance Attribute Details
#category ⇒ Object (readonly)
Returns the value of attribute category.
3 4 5 |
# File 'lib/dentaku/token.rb', line 3 def category @category end |
#raw_value ⇒ Object (readonly)
Returns the value of attribute raw_value.
3 4 5 |
# File 'lib/dentaku/token.rb', line 3 def raw_value @raw_value end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
3 4 5 |
# File 'lib/dentaku/token.rb', line 3 def value @value end |
Instance Method Details
#==(other) ⇒ Object
43 44 45 46 |
# File 'lib/dentaku/token.rb', line 43 def ==(other) (category.nil? || other.category.nil? || category == other.category) && (value.nil? || other.value.nil? || value == other.value) end |
#close? ⇒ Boolean
35 36 37 |
# File 'lib/dentaku/token.rb', line 35 def close? grouping? && value == :close end |
#empty? ⇒ Boolean
19 20 21 |
# File 'lib/dentaku/token.rb', line 19 def empty? length.zero? end |
#grouping? ⇒ Boolean
27 28 29 |
# File 'lib/dentaku/token.rb', line 27 def grouping? is?(:grouping) end |
#is?(c) ⇒ Boolean
39 40 41 |
# File 'lib/dentaku/token.rb', line 39 def is?(c) category == c end |
#length ⇒ Object
15 16 17 |
# File 'lib/dentaku/token.rb', line 15 def length raw_value.to_s.length end |
#open? ⇒ Boolean
31 32 33 |
# File 'lib/dentaku/token.rb', line 31 def open? grouping? && value == :open end |
#operator? ⇒ Boolean
23 24 25 |
# File 'lib/dentaku/token.rb', line 23 def operator? is?(:operator) end |
#to_s ⇒ Object
11 12 13 |
# File 'lib/dentaku/token.rb', line 11 def to_s raw_value || value end |