Class: ImgToPdf::CliOption

Inherits:
Struct
  • Object
show all
Defined in:
lib/img_to_pdf/cli_option.rb

Constant Summary collapse

<<EOS.chomp
Usage: #{File.basename(Process.argv0)} [options] input_image_path output_pdf_path
EOS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#debugObject

Returns the value of attribute debug

Returns:

  • (Object)

    the current value of debug



5
6
7
# File 'lib/img_to_pdf/cli_option.rb', line 5

def debug
  @debug
end

#input_pathObject

Returns the value of attribute input_path

Returns:

  • (Object)

    the current value of input_path



5
6
7
# File 'lib/img_to_pdf/cli_option.rb', line 5

def input_path
  @input_path
end

#margin_ptObject

Returns the value of attribute margin_pt

Returns:

  • (Object)

    the current value of margin_pt



5
6
7
# File 'lib/img_to_pdf/cli_option.rb', line 5

def margin_pt
  @margin_pt
end

#n_horizontal_pagesObject

Returns the value of attribute n_horizontal_pages

Returns:

  • (Object)

    the current value of 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_pagesObject

Returns the value of attribute n_vertical_pages

Returns:

  • (Object)

    the current value of 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_pathObject

Returns the value of attribute output_path

Returns:

  • (Object)

    the current value of output_path



5
6
7
# File 'lib/img_to_pdf/cli_option.rb', line 5

def output_path
  @output_path
end

#paper_size_textObject

Returns the value of attribute paper_size_text

Returns:

  • (Object)

    the current value of 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

.defaultObject



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 = 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).expand_path
  result.output_path = Pathname(output_path).expand_path

  return result
end