Class: Frill::List

Inherits:
Object
  • Object
show all
Defined in:
lib/frill/frill.rb

Defined Under Namespace

Classes: Node

Instance Method Summary collapse

Constructor Details

#initializeList

Returns a new instance of List.



40
41
42
# File 'lib/frill/frill.rb', line 40

def initialize
  @nodes = {}
end

Instance Method Details

#[](label) ⇒ Object



66
67
68
# File 'lib/frill/frill.rb', line 66

def [](label)
  @nodes[label]
end

#add(label) ⇒ Object



44
45
46
# File 'lib/frill/frill.rb', line 44

def add label
  @nodes[label] ||= Node.new label
end

#empty?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/frill/frill.rb', line 70

def empty?
  @nodes.empty?
end

#include?(label) ⇒ Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/frill/frill.rb', line 74

def include? label
  @nodes.keys.include? label
end

#index(label) ⇒ Object



78
79
80
# File 'lib/frill/frill.rb', line 78

def index label
  to_a.index label
end

#move_after(label1, label2) ⇒ Object



57
58
59
60
61
62
63
64
# File 'lib/frill/frill.rb', line 57

def move_after label1, label2
  node1 = add label1
  node2 = add label2

  node1.move_after node2

  detect_cycles
end

#move_before(label1, label2) ⇒ Object



48
49
50
51
52
53
54
55
# File 'lib/frill/frill.rb', line 48

def move_before label1, label2
  node1 = add label1
  node2 = add label2

  node1.move_before node2

  detect_cycles
end

#to_aObject



82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/frill/frill.rb', line 82

def to_a
  lists = []

  @nodes.values.each do |node|
    unless lists.include? node.label
      first = node.first
      lists += first.to_a
    end
  end

  lists
end