Class: Chawan::Node

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

Direct Known Subclasses

Analyzers::MecabAnalyzer::Node

Defined Under Namespace

Modules: GatewayInterface

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from GatewayInterface

#noun?, #verb?

Constructor Details

#initialize(vals, keys) ⇒ Node

Returns a new instance of Node.



18
19
20
21
# File 'lib/chawan/node.rb', line 18

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

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



27
28
29
30
31
32
33
34
# File 'lib/chawan/node.rb', line 27

def [](index)
  case index
  when Integer
    vals[keys[index]]
  else
    attributes[index.to_s]
  end
end

#attributesObject



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

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

#categoryObject



40
41
42
# File 'lib/chawan/node.rb', line 40

def category
  vals[1]
end

#inspectObject



48
49
50
# File 'lib/chawan/node.rb', line 48

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

#to_sObject



44
45
46
# File 'lib/chawan/node.rb', line 44

def to_s
  word
end

#wordObject



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

def word
  vals.first.to_s
end