Class: NLP::Category

Inherits:
Object
  • Object
show all
Defined in:
lib/dictionaries/category.rb

Direct Known Subclasses

LIWCCategory, RIDCategory

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, parent = nil) ⇒ Category

Returns a new instance of Category.



5
6
7
8
# File 'lib/dictionaries/category.rb', line 5

def initialize(name, parent = nil)
  @parent = parent
  @name = name.to_sym
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/dictionaries/category.rb', line 3

def name
  @name
end

#parentObject (readonly)

Returns the value of attribute parent.



3
4
5
# File 'lib/dictionaries/category.rb', line 3

def parent
  @parent
end

Instance Method Details

#pathObject



10
11
12
# File 'lib/dictionaries/category.rb', line 10

def path
  @parent ? (@parent.path + '/' + name.to_s) : name.to_s
end

#rootObject



14
15
16
17
18
19
20
# File 'lib/dictionaries/category.rb', line 14

def root
  category = self
  while category.parent != nil
    category = category.parent
  end
  category.name
end

#to_sObject



22
23
24
# File 'lib/dictionaries/category.rb', line 22

def to_s
  "#{path.inspect}"
end