Class: Rpa::Options
- Inherits:
-
Object
- Object
- Rpa::Options
- Defined in:
- lib/rpa/options.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(args) ⇒ Options
constructor
A new instance of Options.
- #parse! ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize(args) ⇒ Options
Returns a new instance of Options.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/rpa/options.rb', line 9 def initialize(args) @args = args.dup # set the default options @options = { :in_dir => File.('.'), :verbose => false, :title => "Ruby Photo Album", :theme => "galleriffic", :list_themes => false } end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
6 7 8 |
# File 'lib/rpa/options.rb', line 6 def args @args end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/rpa/options.rb', line 6 def @options end |
Instance Method Details
#parse! ⇒ Object
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 |
# File 'lib/rpa/options.rb', line 21 def parse! OptionParser.new do |opts| opts. = "Usage: $ rpa [options]\n\n" + "rpa is Ruby Photo Album (Generator)\n\n" + "Default values:\n" + @options.map {|v| "\t#{v[0]} = #{v[1]}" }.join("\n") + "\n\nOptions:" # required arguments opts.on("-o", "--out-dir [OUT_DIR]") do |arg| @options[:out_dir] = arg end # optional arguments opts.on("-i", "--in-dir [IN_DIR]") do |arg| @options[:in_dir] = arg end opts.on("-v", "--[no-]verbose") do |arg| @options[:verbose] = arg end opts.on("-t", "--title [TITLE]") do |arg| @options[:title] = arg end opts.on("-s", "--subtitle [SUBTITLE]") do |arg| @options[:subtitle] = arg end opts.on("--theme [THEME]") do |arg| @options[:theme] = arg end opts.on("-l", "--[no-]list", "list themes") do |arg| @options[:list_themes] = arg end opts.on_tail("--help") do puts opts exit 0 end end.parse!(args) validate! self end |
#validate! ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/rpa/options.rb', line 68 def validate! # validate options if @options[:in_dir].to_s.strip == "" || !File.directory?(@options[:in_dir]) raise "IN_DIR is required." end end |