Class: Mycommands::Category
- Inherits:
-
Object
- Object
- Mycommands::Category
- Defined in:
- lib/mycommands/models/category.rb
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #children ⇒ Object
- #children=(children) ⇒ Object
- #has_children? ⇒ Boolean
-
#initialize(category) ⇒ Category
constructor
A new instance of Category.
- #name ⇒ Object
- #to_hash ⇒ Object
Constructor Details
Instance Method Details
#<=>(other) ⇒ Object
69 70 71 |
# File 'lib/mycommands/models/category.rb', line 69 def <=> other self.name <=> other.name end |
#children ⇒ Object
53 54 55 |
# File 'lib/mycommands/models/category.rb', line 53 def children @category[1] end |
#children=(children) ⇒ Object
57 58 59 |
# File 'lib/mycommands/models/category.rb', line 57 def children= children @category[1] = children end |
#has_children? ⇒ Boolean
61 62 63 |
# File 'lib/mycommands/models/category.rb', line 61 def has_children? !children.nil? end |
#name ⇒ Object
65 66 67 |
# File 'lib/mycommands/models/category.rb', line 65 def name @category[0] end |
#to_hash ⇒ Object
73 74 75 |
# File 'lib/mycommands/models/category.rb', line 73 def to_hash {@category[0] => has_children? ? children.inject({}) {|category_hash, c| category_hash.merge!(c.to_hash)} : nil } end |