Class: TodoNext::Tree::ParentsList

Inherits:
Object
  • Object
show all
Defined in:
lib/todo_next/tree/parents_list.rb

Instance Method Summary collapse

Constructor Details

#initialize(parents = nil) ⇒ ParentsList

Returns a new instance of ParentsList.



5
6
7
# File 'lib/todo_next/tree/parents_list.rb', line 5

def initialize(parents=nil)
  @parents = parents || { -1 => nil }
end

Instance Method Details

#get_for_item_at_column(curr_col) ⇒ Object



15
16
17
18
# File 'lib/todo_next/tree/parents_list.rb', line 15

def get_for_item_at_column(curr_col)
  parent_key = @parents.keys.sort.reverse.detect {|col| col <= curr_col}
  @parents[parent_key]
end

#register_parent(new_parent, options) ⇒ Object



9
10
11
12
13
# File 'lib/todo_next/tree/parents_list.rb', line 9

def register_parent(new_parent, options)
  curr_col = options.fetch(:for_col)
  @parents[1+curr_col] = new_parent
  @parents.delete_if{|k, v| k > 1+curr_col }
end