Class: Rudo::List

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeList



5
6
7
8
# File 'lib/rudo/list.rb', line 5

def initialize
  self.file_path = File.expand_path('~/rudo.yml')
  self.tasks = YAML.load(File.read(file_path))
end

Instance Attribute Details

#tasksObject

Returns the value of attribute tasks.



3
4
5
# File 'lib/rudo/list.rb', line 3

def tasks
  @tasks
end

Instance Method Details

#add(task) ⇒ Object



14
15
16
17
# File 'lib/rudo/list.rb', line 14

def add(task)
  tasks << task
  write_tasks
end

#firstObject



42
43
44
# File 'lib/rudo/list.rb', line 42

def first
  tasks.first
end

#lastObject



38
39
40
# File 'lib/rudo/list.rb', line 38

def last
  tasks.last
end

#lengthObject



10
11
12
# File 'lib/rudo/list.rb', line 10

def length
  tasks.length
end

#prepend(task) ⇒ Object



19
20
21
22
# File 'lib/rudo/list.rb', line 19

def prepend(task)
  tasks.unshift(task)
  write_tasks
end

#remove(arg = 0) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/rudo/list.rb', line 24

def remove(arg=0)
  if arg.to_s =~ /^(\d+)x$/
    $1.to_i.times { tasks.shift }
  else
    tasks.delete_at(arg.to_i)
  end
  write_tasks
end

#to_sObject



46
47
48
49
50
51
52
53
54
# File 'lib/rudo/list.rb', line 46

def to_s
  string = "#{stars}\n"
  tasks.each_with_index do |task, index|
    string << "#{index + 1}: #{task}\n"
  end

  string << "#{stars}\n"
  string << "#{tasks.length} tasks remaining".green
end

#walk(count = 1) ⇒ Object



33
34
35
36
# File 'lib/rudo/list.rb', line 33

def walk(count=1)
  count.to_i.times { tasks << tasks.shift }
  write_tasks
end