Class: Chawan::Node
- Inherits:
-
Object
show all
- Defined in:
- lib/chawan/node.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(vals, keys) ⇒ Node
Returns a new instance of Node.
6
7
8
9
|
# File 'lib/chawan/node.rb', line 6
def initialize(vals, keys)
@vals = vals
@keys = keys
end
|
Instance Attribute Details
#keys ⇒ Object
Returns the value of attribute keys.
4
5
6
|
# File 'lib/chawan/node.rb', line 4
def keys
@keys
end
|
#vals ⇒ Object
Returns the value of attribute vals.
3
4
5
|
# File 'lib/chawan/node.rb', line 3
def vals
@vals
end
|
Instance Method Details
#[](index) ⇒ Object
15
16
17
18
19
20
21
22
|
# File 'lib/chawan/node.rb', line 15
def [](index)
case index
when Integer
vals[keys[index]]
else
attributes[index.to_s]
end
end
|
#attributes ⇒ Object
11
12
13
|
# File 'lib/chawan/node.rb', line 11
def attributes
@attributes ||= Hash[*keys.zip(vals).flatten]
end
|
#category ⇒ Object
28
29
30
|
# File 'lib/chawan/node.rb', line 28
def category
vals[1]
end
|
#inspect ⇒ Object
36
37
38
|
# File 'lib/chawan/node.rb', line 36
def inspect
"<%s: '%s'>" % [category, to_s]
end
|
#to_s ⇒ Object
32
33
34
|
# File 'lib/chawan/node.rb', line 32
def to_s
word
end
|
#word ⇒ Object
24
25
26
|
# File 'lib/chawan/node.rb', line 24
def word
vals.first.to_s
end
|