Class: Worklog::CLI

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/worklog/cli.rb

Instance Method Summary collapse

Instance Method Details

#getObject



45
46
47
# File 'lib/worklog/cli.rb', line 45

def get
  get_logs.each{|sh| Printer.new(Decorator.new(sh)).tracks()}
end

#indexObject



80
81
82
83
# File 'lib/worklog/cli.rb', line 80

def index
  str = Worklog.params[:index].map{|i| "- #{i}"}.join(?n)
  say "Worklogs were noticed in the following places:\n#{str}"
end

#new(logname = File.basename(Dir.pwd)) ⇒ Object



37
38
39
40
41
42
# File 'lib/worklog/cli.rb', line 37

def new(logname = File.basename(Dir.pwd))
  filename = CreateLog.(logname)
  exit if filename.empty?
  say "Worklog #{filename} created"
  Worklog.indexd
end

#prev(period = "month") ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/worklog/cli.rb', line 65

def prev(period = "month")
  get_logs.each do |sh|
    printer = Printer.new(Decorator.new(sh))
    case period
    when 'month'
      printer.prev_month
    when 'week'
      printer.prev_week
    else
      raise ArgumentError, "Unknown period '#{period}'"
    end
  end
end

#this(period = "month") ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/worklog/cli.rb', line 50

def this(period = "month")
  get_logs.each do |sh|
    printer = Printer.new(Decorator.new(sh))
    case period
    when 'month'
      printer.this_month
    when 'week'
      printer.this_week
    else
      raise ArgumentError, "Unknown period '#{period}'"
    end
  end
end

#versionObject



31
32
33
# File 'lib/worklog/cli.rb', line 31

def version
  puts "Worklog v#{Worklog::VERSION}"
end