Class: Rledger::Runner
- Inherits:
-
Object
- Object
- Rledger::Runner
- Defined in:
- lib/rledger.rb
Class Method Summary collapse
-
.parse(args) ⇒ Object
parse command line.
-
.run(args) ⇒ Object
run: interpret command line and execute.
Class Method Details
.parse(args) ⇒ Object
parse command line
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 |
# File 'lib/rledger.rb', line 12 def self.parse(args) = Hash.new opt_parser = OptionParser.new do |opts| opts. = "Usage: rledger [options]" opts.separator "" opts.separator "Specific options:" opts.on("-c", "--command STRING", String, "Command (one of check, statement, balance)") do |command| [:command] = command end opts.on("-v", "--voice VOICE", String, "Voice") do |voice| [:voice] = voice end #opts.on("-f", "--from_date DATE", Date, "From date") do |from_date| # options[:from_date] = from_date #end #opts.on("-to", "--to_date DATE", Date, "To date") do |to_date| # options[:to_date] = to_date #end opts.on( '-h', '--help', 'Display this screen' ) do puts opts puts "Reads a ledger (http://www.ledger-cli.org) and performs simple operations.\n\nOnly the basic format is recognized: do not expect this gem to perform well\nwith virtual transactions. Different date formats and different currencies\nshould, however, be supported.\n\nExample usages\n\n rledger --command statement ledger.txt\n rledger --command balance ledger.txt\n\n" exit end end opt_parser.parse!(args) end |
.run(args) ⇒ Object
run: interpret command line and execute
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/rledger.rb', line 61 def self.run(args) # read options = parse(args) # read data data = [] ARGV.each do |argv| data += Transaction.read(argv) end # now do case [:command] when "check" puts "This is what I understand from the input files:\n" data.each do |transaction| printf "%s\n", transaction.to_s end when "statement" report = Statement.new(data) report.compute([:voice]) puts "Statement of #{options[:voice]}" puts report when "balance" report = Balance.new(data) report.compute puts report else puts "Oh, I wish I could understand what you mean." puts "Try with --help." end end |