Class: Financo::CLI::Program::Parser
- Inherits:
-
Object
- Object
- Financo::CLI::Program::Parser
- Defined in:
- lib/financo/cli/program/parser.rb
Overview
Parser
Constant Summary collapse
- DEFAULT_CHECKING =
'Bank:Checking'- DEFAULT_OUTPUT =
'journal-<timestamp>.ledger'
Instance Method Summary collapse
- #help ⇒ Object
-
#initialize ⇒ Parser
constructor
A new instance of Parser.
- #parse(argv) ⇒ Object
Constructor Details
#initialize ⇒ Parser
Returns a new instance of Parser.
11 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 |
# File 'lib/financo/cli/program/parser.rb', line 11 def initialize @op = OptionParser.new @op. = 'Download and convert N26 bank transactions into a ' \ 'Ledger journal' @op.separator( StringIO.open do |s| s.puts s.puts 'Options:' s.string end ) @op.on( '--checking ACCOUNT_NAME', "bank checking account (default '#{DEFAULT_CHECKING}')" ) @op.on( '-o', '--output OUTPUT', "journal output: filename or STDOUT (default: #{DEFAULT_OUTPUT})" ) @op.on('-v', '--version', 'show version') @op.on('-h', '--help', 'show this message') @op.separator( StringIO.open do |s| s.puts s.puts 'Usage:' s.puts ' financo [options] <username> <password>' s.string end ) end |
Instance Method Details
#help ⇒ Object
63 64 65 |
# File 'lib/financo/cli/program/parser.rb', line 63 def help @op.to_s end |
#parse(argv) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/financo/cli/program/parser.rb', line 46 def parse(argv) = { checking: DEFAULT_CHECKING, output: DEFAULT_OUTPUT.sub('<timestamp>', Time.now.to_i.to_s) } args = @op.parse(argv, into: ) unless [:help] || [:version] raise ParserError, "expected: '<username> <password>'." if args.length != 2 end [args, ] rescue OptionParser::MissingArgument => e raise ParserError, e end |