Class: NLP::Category
- Inherits:
-
Object
- Object
- NLP::Category
- Defined in:
- lib/dictionaries/category.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Instance Method Summary collapse
-
#initialize(name, parent = nil) ⇒ Category
constructor
A new instance of Category.
- #path ⇒ Object
- #root ⇒ Object
- #to_s ⇒ Object
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
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/dictionaries/category.rb', line 3 def name @name end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
3 4 5 |
# File 'lib/dictionaries/category.rb', line 3 def parent @parent end |
Instance Method Details
#path ⇒ Object
10 11 12 |
# File 'lib/dictionaries/category.rb', line 10 def path @parent ? (@parent.path + '/' + name.to_s) : name.to_s end |
#root ⇒ Object
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_s ⇒ Object
22 23 24 |
# File 'lib/dictionaries/category.rb', line 22 def to_s "#{path.inspect}" end |