Class: HTOTConv::CLI::ScriptOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/htot_conv/cli.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeScriptOptions

Returns a new instance of ScriptOptions.



9
10
11
12
13
14
15
16
# File 'lib/htot_conv/cli.rb', line 9

def initialize
  @options = {
    :from_type => :simple_text,
    :to_type => :xlsx_type2,
  }
  @from_options = {}
  @to_options = {}
end

Instance Attribute Details

#from_optionsObject (readonly)

Returns the value of attribute from_options.



17
18
19
# File 'lib/htot_conv/cli.rb', line 17

def from_options
  @from_options
end

#optionsObject (readonly)

Returns the value of attribute options.



17
18
19
# File 'lib/htot_conv/cli.rb', line 17

def options
  @options
end

#to_optionsObject (readonly)

Returns the value of attribute to_options.



17
18
19
# File 'lib/htot_conv/cli.rb', line 17

def to_options
  @to_options
end

Instance Method Details

#define_options(opts, io_filter = false) ⇒ Object



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
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/htot_conv/cli.rb', line 26

def define_options(opts, io_filter=false)
  opts.banner       = %q{Hierarchical-Tree Outline Text Converter}
  opts.define_head    %q{Usage: htot_conv [options] [input] [output]}
  opts.separator      %q{}
  opts.separator      %q{Options:}

  from_types = HTOTConv::Parser.types.map { |v| [v, v.to_s.tr("_", "-")] }.flatten
  to_types = HTOTConv::Generator.types.map { |v| [v, v.to_s.tr("_", "-")] }.flatten

  opts.on("-f", "--from-type=TYPE", from_types, "type of input (default: #{options[:from_type]})") do |v|
    @options[:from_type] = v.to_s.tr("-", "_")
  end
  opts.on("-t", "--to-type=TYPE", to_types, "type of output (default: #{options[:to_type]})") do |v|
    @options[:to_type] = v.to_s.tr("-", "_")
  end
  opts.on("-l", "--list-type", "list input/output type") do
    $stdout << "type of input:\n"
    $stdout << HTOTConv::Parser.types.join(" ") << "\n"
    $stdout << "\n"
    $stdout << "type of output:\n"
    $stdout << HTOTConv::Generator.types.join(" ") << "\n"
    $stdout << "\n"
    exit
  end

  opts.separator ""
  opts.on("-h", "-?", "--help", "Show this message") do
    puts opts
    exit
  end
  opts.on("--version", "Show version") do
    $stdout << "htot_conv #{HTOTConv::VERSION}\n"
    exit
  end

  opts.separator ""
  opts.separator "I/O Options:"
  if io_filter
    define_sub_options_of(opts, HTOTConv::Parser, @options[:from_type], "from") do |key, v|
      @from_options[key] = v
    end
    define_sub_options_of(opts, HTOTConv::Generator, @options[:to_type], "to") do |key, v|
      @to_options[key] = v
    end
  else
    define_sub_options(opts, HTOTConv::Parser, "from") do |key, v|
      @from_options[key] = v
    end
    define_sub_options(opts, HTOTConv::Generator, "to") do |key, v|
      @to_options[key] = v
    end
  end
end

#freezeObject



19
20
21
22
23
24
# File 'lib/htot_conv/cli.rb', line 19

def freeze
  @options.freeze
  @from_options.freeze
  @to_options.freeze
  super
end