Class: ImageSite::Options
- Inherits:
-
Object
- Object
- ImageSite::Options
- Defined in:
- lib/image_site/options.rb
Constant Summary collapse
- DEFAULT_COLUMNS =
4
- DEFAULT_ROWS =
10
Instance Attribute Summary collapse
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
-
#descriptions_on_index_pages ⇒ Object
readonly
Returns the value of attribute descriptions_on_index_pages.
-
#files ⇒ Object
readonly
Returns the value of attribute files.
-
#output_dir ⇒ Object
readonly
Returns the value of attribute output_dir.
-
#parent_link_text ⇒ Object
readonly
Returns the value of attribute parent_link_text.
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Instance Method Summary collapse
- #abort_with_help(parser, message) ⇒ Object
-
#initialize ⇒ Options
constructor
A new instance of Options.
- #parse! ⇒ Object
Constructor Details
#initialize ⇒ Options
Returns a new instance of Options.
10 11 12 13 14 15 16 17 |
# File 'lib/image_site/options.rb', line 10 def initialize @title = nil @columns = DEFAULT_COLUMNS @rows = DEFAULT_ROWS @descriptions_on_index_pages = false @parent_link_text = nil @output_dir = nil end |
Instance Attribute Details
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
8 9 10 |
# File 'lib/image_site/options.rb', line 8 def columns @columns end |
#descriptions_on_index_pages ⇒ Object (readonly)
Returns the value of attribute descriptions_on_index_pages.
8 9 10 |
# File 'lib/image_site/options.rb', line 8 def descriptions_on_index_pages @descriptions_on_index_pages end |
#files ⇒ Object (readonly)
Returns the value of attribute files.
8 9 10 |
# File 'lib/image_site/options.rb', line 8 def files @files end |
#output_dir ⇒ Object (readonly)
Returns the value of attribute output_dir.
8 9 10 |
# File 'lib/image_site/options.rb', line 8 def output_dir @output_dir end |
#parent_link_text ⇒ Object (readonly)
Returns the value of attribute parent_link_text.
8 9 10 |
# File 'lib/image_site/options.rb', line 8 def parent_link_text @parent_link_text end |
#rows ⇒ Object (readonly)
Returns the value of attribute rows.
8 9 10 |
# File 'lib/image_site/options.rb', line 8 def rows @rows end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
8 9 10 |
# File 'lib/image_site/options.rb', line 8 def title @title end |
Instance Method Details
#abort_with_help(parser, message) ⇒ Object
67 68 69 |
# File 'lib/image_site/options.rb', line 67 def abort_with_help(parser, ) abort "#{}\n#{parser}" end |
#parse! ⇒ Object
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 |
# File 'lib/image_site/options.rb', line 19 def parse! parser = OptionParser.new do |op| op. = "Usage: #{$PROGRAM_NAME} -t TITLE -o OUTPUT_DIR [other options] file [...]" op.on('-t TITLE', "Title of the set of images") do |title| @title = title end op.on('-c COLUMNS', "The number of columns of thumbnails on each index page (default #{DEFAULT_COLUMNS})") do |columns| @columns = columns.to_i end op.on('-r ROWS', "The number of rows of photos on each index page (default #{DEFAULT_ROWS})") do |rows| @rows = rows.to_i end op.on('-d', "Descriptions are included on index pages") do @descriptions_on_index_pages = true end op.on('-p PARENT_LINK_TEXT', "The text of the link to ../ on the last index page") do |parent_link_text| @parent_link_text = parent_link_text end op.on('-o OUTPUT_DIR', "Output directory") do |output_dir| @output_dir = output_dir end # -h and --help work by default, but implement them explicitly so they're # documented op.on("-h", "--help", "Prints this help") do warn op.to_s exit end end begin parser.parse! rescue OptionParser::ParseError abort parser.to_s end if !@title abort_with_help parser, "Please specify a title with -t." end if !@output_dir abort_with_help parser, "Please specify an output directory with -o." end if ARGV.empty? abort_with_help parser, "Please specify one or more image files." end @files = ARGV end |