Class: Rudo::List
- Inherits:
-
Object
- Object
- Rudo::List
- Defined in:
- lib/rudo/list.rb
Instance Attribute Summary collapse
-
#tasks ⇒ Object
Returns the value of attribute tasks.
Instance Method Summary collapse
- #add(task) ⇒ Object
- #first ⇒ Object
-
#initialize ⇒ List
constructor
A new instance of List.
- #last ⇒ Object
- #length ⇒ Object
- #prepend(task) ⇒ Object
- #remove(arg = 0) ⇒ Object
- #to_s ⇒ Object
- #walk(count = 1) ⇒ Object
Constructor Details
#initialize ⇒ List
5 6 7 8 |
# File 'lib/rudo/list.rb', line 5 def initialize self.file_path = File.('~/rudo.yml') self.tasks = YAML.load(File.read(file_path)) end |
Instance Attribute Details
#tasks ⇒ Object
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 |
#first ⇒ Object
42 43 44 |
# File 'lib/rudo/list.rb', line 42 def first tasks.first end |
#last ⇒ Object
38 39 40 |
# File 'lib/rudo/list.rb', line 38 def last tasks.last end |
#length ⇒ Object
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_s ⇒ Object
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 |