Class: TextInvoice::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/text-invoice/cli.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCLI

Returns a new instance of CLI.



7
8
9
10
11
# File 'lib/text-invoice/cli.rb', line 7

def initialize()
    @tasks = TextInvoice::Tasks.new
    @argv = ARGV
    @stdin = $stdin
end

Instance Attribute Details

#argvObject

Returns the value of attribute argv.



5
6
7
# File 'lib/text-invoice/cli.rb', line 5

def argv
  @argv
end

#stdinObject

Returns the value of attribute stdin.



5
6
7
# File 'lib/text-invoice/cli.rb', line 5

def stdin
  @stdin
end

#tasksObject

Returns the value of attribute tasks.



5
6
7
# File 'lib/text-invoice/cli.rb', line 5

def tasks
  @tasks
end

Instance Method Details

#runObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/text-invoice/cli.rb', line 13

def run()
  mode = @argv.shift
  if mode == "update"
      @tasks.totals(@stdin.read)
  elsif mode == "summary"
      @tasks.summary(@argv)
  elsif mode == "list"
      @tasks.list(@argv)
  elsif mode == "new"
      @tasks.new_invoice()
  elsif mode == "html"
      @tasks.html(@stdin.read)
  elsif mode == "template"
      template = @argv.shift
      if template
          @tasks.template(@stdin.read, template)
      else
          @tasks.usage()
      end
  else
      @tasks.usage()
  end
end