Class: Rudo
- Inherits:
-
Object
- Object
- Rudo
- Defined in:
- lib/rudo.rb,
lib/rudo/list.rb
Defined Under Namespace
Classes: List
Instance Method Summary collapse
- #add(task, position = nil) ⇒ Object
-
#initialize(options = {}) ⇒ Rudo
constructor
A new instance of Rudo.
- #remove(position = 1) ⇒ Object
- #to_s ⇒ Object
- #walk(steps = 1) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Rudo
Returns a new instance of Rudo.
7 8 9 10 11 |
# File 'lib/rudo.rb', line 7 def initialize(={}) @file_path = File.(.delete(:file_path) { '~/rudo.yml' }) @tasks = YAML.load(File.read(@file_path)) end |
Instance Method Details
#add(task, position = nil) ⇒ Object
13 14 15 16 17 |
# File 'lib/rudo.rb', line 13 def add(task, position=nil) position ||= @tasks.length @tasks.insert(position, task) write_tasks end |
#remove(position = 1) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rudo.rb', line 19 def remove(position=1) if position.is_a?(String) && position.match(/^(\d+)x/) count = Integer($1) count.times { @tasks.shift } else position = position.to_i position -= 1 if position > 0 @tasks.delete_at(position) end write_tasks end |
#to_s ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/rudo.rb', line 36 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(steps = 1) ⇒ Object
31 32 33 34 |
# File 'lib/rudo.rb', line 31 def walk(steps=1) steps.times { @tasks << @tasks.shift } write_tasks end |