Module: CollectiveIdea::Acts::NestedSet::Descendants

Defined in:
lib/nested_set/descendants.rb

Instance Method Summary collapse

Instance Method Details

#descendants_countObject

Returns the number of nested children of this object.



7
8
9
# File 'lib/nested_set/descendants.rb', line 7

def descendants_count
  return (right - left - 1)/2
end

#has_descendants?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/nested_set/descendants.rb', line 11

def has_descendants?
  !descendants_count.zero?
end

#move_by_direction(ditection) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/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