Class: Chawan::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/chawan/node.rb

Direct Known Subclasses

Analyzers::MecabAnalyzer::Node

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

#keysObject (readonly)

Returns the value of attribute keys.



4
5
6
# File 'lib/chawan/node.rb', line 4

def keys
  @keys
end

#valsObject (readonly)

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

#attributesObject



11
12
13
# File 'lib/chawan/node.rb', line 11

def attributes
  @attributes ||= Hash[*keys.zip(vals).flatten]
end

#categoryObject



28
29
30
# File 'lib/chawan/node.rb', line 28

def category
  vals[1]
end

#inspectObject



36
37
38
# File 'lib/chawan/node.rb', line 36

def inspect
  "<%s: '%s'>" % [category, to_s]
end

#to_sObject



32
33
34
# File 'lib/chawan/node.rb', line 32

def to_s
  word
end

#wordObject



24
25
26
# File 'lib/chawan/node.rb', line 24

def word
  vals.first.to_s
end