Sha256: bbfe1a1e9b8a8bbf73e6fd09720da620e7b0fbae465eaa439ce7ef775a576da2

Contents?: true

Size: 779 Bytes

Versions: 7

Compression:

Stored size: 779 Bytes

Contents

module ExtendedNestedSet
  module InstanceMethods

    def is_first_of_siblings?(parent = nil)
      if parent
        parent.lft == self.lft - 1
      else
        left_sibling.nil?
      end
    end

    def is_last_of_siblings?(parent = nil)
      if parent
        parent.rgt == self.rgt + 1
      else
        right_sibling.nil?
      end
    end

    def move_lower
      move_to_right_of(right_sibling) unless is_last_of_siblings?
    end

    def move_higher
      move_to_left_of left_sibling unless is_first_of_siblings?
    end

    def move_to_bottom
      move_to_right_of siblings.last unless is_last_of_siblings?
    end

    def move_to_top
      move_to_left_of siblings.first unless is_first_of_siblings?
    end

  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
extended_nested_set-0.0.1 lib/extended_nested_set/instance_methods.rb
etabliocms_core-0.0.7 vendor/plugins/extended_nested_set/lib/extended_nested_set.rb
etabliocms_core-0.0.6 vendor/plugins/extended_nested_set/lib/extended_nested_set.rb
etabliocms_core-0.0.5 vendor/plugins/extended_nested_set/lib/extended_nested_set.rb
etabliocms_core-0.0.4 vendor/plugins/extended_nested_set/lib/extended_nested_set.rb
etabliocms_core-0.0.3 vendor/plugins/extended_nested_set/lib/extended_nested_set.rb
etabliocms_core-0.0.2 vendor/plugins/extended_nested_set/lib/extended_nested_set.rb