Class: ImgToPdf::CliOption
- Inherits:
-
Struct
- Object
- Struct
- ImgToPdf::CliOption
- Defined in:
- lib/img_to_pdf/cli_option.rb
Constant Summary collapse
- BANNER =
<<EOS.chomp Usage: #{File.basename(Process.argv0)} [options] input_image_path output_pdf_path EOS
Instance Attribute Summary collapse
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#input_path ⇒ Object
Returns the value of attribute input_path.
-
#margin_pt ⇒ Object
Returns the value of attribute margin_pt.
-
#n_horizontal_pages ⇒ Object
Returns the value of attribute n_horizontal_pages.
-
#n_vertical_pages ⇒ Object
Returns the value of attribute n_vertical_pages.
-
#output_path ⇒ Object
Returns the value of attribute output_path.
-
#paper_size_text ⇒ Object
Returns the value of attribute paper_size_text.
Class Method Summary collapse
Instance Attribute Details
#debug ⇒ Object
Returns the value of attribute debug
5 6 7 |
# File 'lib/img_to_pdf/cli_option.rb', line 5 def debug @debug end |
#input_path ⇒ Object
Returns the value of attribute input_path
5 6 7 |
# File 'lib/img_to_pdf/cli_option.rb', line 5 def input_path @input_path end |
#margin_pt ⇒ Object
Returns the value of attribute margin_pt
5 6 7 |
# File 'lib/img_to_pdf/cli_option.rb', line 5 def margin_pt @margin_pt end |
#n_horizontal_pages ⇒ Object
Returns the value of attribute n_horizontal_pages
5 6 7 |
# File 'lib/img_to_pdf/cli_option.rb', line 5 def n_horizontal_pages @n_horizontal_pages end |
#n_vertical_pages ⇒ Object
Returns the value of attribute n_vertical_pages
5 6 7 |
# File 'lib/img_to_pdf/cli_option.rb', line 5 def n_vertical_pages @n_vertical_pages end |
#output_path ⇒ Object
Returns the value of attribute output_path
5 6 7 |
# File 'lib/img_to_pdf/cli_option.rb', line 5 def output_path @output_path end |
#paper_size_text ⇒ Object
Returns the value of attribute paper_size_text
5 6 7 |
# File 'lib/img_to_pdf/cli_option.rb', line 5 def paper_size_text @paper_size_text end |
Class Method Details
.default ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/img_to_pdf/cli_option.rb', line 14 def default default_margin_pt = ImgToPdf::Unit.convert_mm_to_pt(10) return new( input_path: nil, output_path: nil, debug: false, paper_size_text: "a4-landscape", margin_pt: ImgToPdf::Margin.new( left: default_margin_pt, right: default_margin_pt, top: default_margin_pt, bottom: default_margin_pt, ), n_horizontal_pages: 1, n_vertical_pages: 1, ) end |
.from_argv(argv, stdout: STDOUT) ⇒ Object
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/img_to_pdf/cli_option.rb', line 32 def from_argv(argv, stdout: STDOUT) result = default parser = OptionParser.new parser.version = ImgToPdf::VERSION parser. = BANNER parser.summary_indent = "" parser.separator("") parser.separator("Options:") parser.on("--paper-size=SIZE", "specify paper size. 'a4-landscape'(default), 'b3-portrait', etc.") do |v| result.paper_size_text = v end parser.on("--horizontal-pages=INTEGER", "specify number of horizontal pages. default 1.") do |v| result.n_horizontal_pages = ImgToPdf::IntegerParser.(v) end parser.on("--vertical-pages=INTEGER", "specify number of vertical pages. default 1.") do |v| result.n_vertical_pages = ImgToPdf::IntegerParser.(v) end parser.on("--debug") do result.debug = true end input_path, output_path = *parser.parse(argv) if !output_path stdout.puts(parser.help) exit(1) end result.input_path = Pathname(input_path). result.output_path = Pathname(output_path). return result end |