Class: Transaction::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/transactions/options.rb

Instance Method Summary collapse

Constructor Details

#initializeOptions

Returns a new instance of Options.



5
6
7
# File 'lib/transactions/options.rb', line 5

def initialize
  @options = {}
end

Instance Method Details

#commands_helpObject

Internal: Prints help for commands that are stored in ARGV. Used in help menu.

Returns nothing.



78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/transactions/options.rb', line 78

def commands_help
  <<-COMMANDHELP

  COMMANDS
  --------
  balance [ACCOUNT]..   Prints account balances, limited to ACCOUNTS.
                        'bal' can be used as a shortcut.
  register [ACCOUNT]..  Prints account register, limited to ACCOUNTS.
                        'reg' can be used as a shortcut.
  print                 Prints transactions formatted for export to ledger.
                        Can be limited by date but not ACCOUNT.
  COMMANDHELP
end

#optionsObject

Internal: Parses options for transactions from the command line.

Returns nothing.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/transactions/options.rb', line 12

def options
  OptionParser.new do |opts|

    opts.banner = "Usage: transactions [options] COMMAND [ARGS] ..."

    opts.on("-f", "--file PATH", "PATH to yaml file to parse") do |x|
      @options[:file] = x
    end

    opts.on("-c", "--current",
            "don't include entries with future dates") do |x|
      @options[:current] = x
    end

    opts.on("-b", "--begin DATE", "set begin date, DATE: YYYY/MM/DD") do |x|
      @options[:begin] = x
    end

    opts.on("-e", "--end DATE", "set end date, DATE: YYYY/MM/DD") do |x|
      @options[:end] = x
    end

    opts.on("-s", "--subtotal", "show sub-totals for balance") do |x|
      @options[:subtotal] = x
    end

    opts.on("-E", "--empty", "show accounts with zero balance") do |x|
      @options[:empty] = x
    end

    opts.on("-S", "--sort ARG", "sort by field, ARG can be date or tran") do |x|
      @options[:sort] = x
    end

    opts.on("-w", "--wide", "print 132 columns wide for register") do |x|
      @options[:wide] = x
    end

    #opts.on("-C", "--cleared", "only include cleared transactions") do |x|
    #  @options[:cleared] = x
    #end

    #opts.on("-U", "--uncleared", "only include uncleared transactions") do |x|
    #  @options[:uncleared] = x
    #end

    opts.on_tail("-h", "--help", "show this help message") do
      puts opts
      abort self.commands_help
    end

    opts.on_tail("-v", "--version", "show version") do
      abort "#{Transaction::VERSION}"
    end

  end.parse!

  @options

end