Class: WorkGuide::CLI
- Inherits:
-
Thor
- Object
- Thor
- WorkGuide::CLI
- Defined in:
- lib/work_guide/cli.rb
Instance Method Summary collapse
- #add(description) ⇒ Object
- #delete(index = nil) ⇒ Object
- #done(*args) ⇒ Object
- #list ⇒ Object
- #update(index = nil) ⇒ Object
Instance Method Details
#add(description) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/work_guide/cli.rb', line 10 def add(description) guide = Guide.create( description: description, priority: [:priority], cycle: [:cycle], week_start: [:week_start] ) puts "Created [#{Guide.all.size - 1}]#{guide}" end |
#delete(index = nil) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/work_guide/cli.rb', line 42 def delete(index = nil) index = boot_peco(all: true) unless index.present? guide = Guide.all.delete_at(index.to_i) Guide.save puts "Deleted [#{index}]#{guide}" end |
#done(*args) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/work_guide/cli.rb', line 51 def done(*args) indexes = args.dup indexes << boot_peco if indexes.empty? guides = indexes.map { |index| Guide.all[index.to_i] } done_at = if [:at] Time.parse([:at]) else Time.now end guides.each do |guide| guide.done_at = done_at end Guide.save indexes.each do |index| puts "Done [#{index}]#{Guide.all[index.to_i]}" end end |
#list ⇒ Object
36 37 38 |
# File 'lib/work_guide/cli.rb', line 36 def list puts guide_table(all: [:all]) end |
#update(index = nil) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/work_guide/cli.rb', line 24 def update(index = nil) index = boot_peco(all: true) unless index.present? guide = Guide.all[index.to_i] guide.priority = [:priority] if [:priority] guide.cycle = [:cycle] if [:cycle] guide.week_start = [:week_start] if [:week_start] Guide.save puts "Update [#{index}]#{guide}" end |