Class: Dentaku::Token

Inherits:
Object
  • Object
show all
Defined in:
lib/dentaku/token.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#categoryObject (readonly)

Returns the value of attribute category.



3
4
5
# File 'lib/dentaku/token.rb', line 3

def category
  @category
end

#raw_valueObject (readonly)

Returns the value of attribute raw_value.



3
4
5
# File 'lib/dentaku/token.rb', line 3

def raw_value
  @raw_value
end

#valueObject (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



31
32
33
34
# File 'lib/dentaku/token.rb', line 31

def ==(other)
  (category.nil? || other.category.nil? || category == other.category) &&
  (value.nil?    || other.value.nil?    || value    == other.value)
end

#empty?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/dentaku/token.rb', line 19

def empty?
  length.zero?
end

#grouping?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/dentaku/token.rb', line 23

def grouping?
  is?(:grouping)
end

#is?(c) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/dentaku/token.rb', line 27

def is?(c)
  category == c
end

#lengthObject



15
16
17
# File 'lib/dentaku/token.rb', line 15

def length
  raw_value.to_s.length
end

#to_sObject



11
12
13
# File 'lib/dentaku/token.rb', line 11

def to_s
  raw_value || value
end