Module: Sunrise::NestedSet::Descendants
- Defined in:
- lib/sunrise/nested_set/descendants.rb
Instance Method Summary collapse
-
#descendants_count ⇒ Object
Returns the number of nested children of this object.
-
#has_descendants? ⇒ Boolean
Check if has descendants.
-
#move_by_direction(ditection) ⇒ Object
Move node up or down (sort).
Instance Method Details
#descendants_count ⇒ Object
Returns the number of nested children of this object.
5 6 7 |
# File 'lib/sunrise/nested_set/descendants.rb', line 5 def descendants_count return (right - left - 1)/2 end |
#has_descendants? ⇒ Boolean
Check if has descendants
10 11 12 |
# File 'lib/sunrise/nested_set/descendants.rb', line 10 def has_descendants? !descendants_count.zero? end |
#move_by_direction(ditection) ⇒ Object
Move node up or down (sort)
15 16 17 18 19 20 21 22 |
# File 'lib/sunrise/nested_set/descendants.rb', line 15 def move_by_direction(ditection) return if ditection.blank? case ditection.to_sym when :up, :left then move_left when :down, :right then move_right end end |