Module: Sunrise::NestedSet::Descendants

Defined in:
lib/sunrise/nested_set/descendants.rb

Instance Method Summary collapse

Instance Method Details

#descendants_countObject

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

Returns:

  • (Boolean)


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