Class: KBS::Token

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent, fact, node) ⇒ Token

Returns a new instance of Token.



7
8
9
10
11
12
13
# File 'lib/kbs/token.rb', line 7

def initialize(parent, fact, node)
  @parent = parent
  @fact = fact
  @node = node
  @children = []
  @fired = false
end

Instance Attribute Details

#childrenObject

Returns the value of attribute children.



5
6
7
# File 'lib/kbs/token.rb', line 5

def children
  @children
end

#factObject

Returns the value of attribute fact.



5
6
7
# File 'lib/kbs/token.rb', line 5

def fact
  @fact
end

#nodeObject

Returns the value of attribute node.



5
6
7
# File 'lib/kbs/token.rb', line 5

def node
  @node
end

#parentObject

Returns the value of attribute parent.



5
6
7
# File 'lib/kbs/token.rb', line 5

def parent
  @parent
end

Instance Method Details

#factsObject



15
16
17
18
19
20
21
22
23
# File 'lib/kbs/token.rb', line 15

def facts
  facts = []
  token = self
  while token
    facts.unshift(token.fact) if token.fact
    token = token.parent
  end
  facts
end

#fired?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/kbs/token.rb', line 29

def fired?
  @fired
end

#mark_fired!Object



33
34
35
# File 'lib/kbs/token.rb', line 33

def mark_fired!
  @fired = true
end

#to_sObject



25
26
27
# File 'lib/kbs/token.rb', line 25

def to_s
  "Token(#{facts.map(&:to_s).join(', ')})"
end