Class: Asciimation::ArgumentParser
- Inherits:
-
Object
- Object
- Asciimation::ArgumentParser
- Defined in:
- lib/asciimation/argument_parser.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
{animator: "drop", duration: 5.0}
Instance Method Summary collapse
-
#initialize(args) ⇒ ArgumentParser
constructor
A new instance of ArgumentParser.
- #to_hash ⇒ Object
Constructor Details
#initialize(args) ⇒ ArgumentParser
Returns a new instance of ArgumentParser.
7 8 9 |
# File 'lib/asciimation/argument_parser.rb', line 7 def initialize(args) @args = args end |
Instance Method Details
#to_hash ⇒ Object
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 |
# File 'lib/asciimation/argument_parser.rb', line 14 def to_hash = DEFAULT_OPTIONS.dup hash = {io: nil, options: } args. do |parser| parser. = "Usage: #{File.basename($PROGRAM_NAME)} [OPTIONS] ASCII_ART_PATH" parser.separator "" parser.separator "Specific Options:" parser.on( "--animator NAME", String, "The animator to use." ) do |animator| [:animator] = animator end parser.on( "-o", "--duration SECONDS", Float, "The seconds this animation should last." ) do |duration| [:duration] = duration end parser.separator "Common Options:" parser.on( "-h", "--help", "Show this message." ) do puts parser exit end begin path = args.shift or abort parser.to_s hash[:io] = open(path) parser.parse! rescue OptionParser::ParseError abort parser.to_s end end hash end |