htot_conv 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5d5f671f2c6eb3e7bc5c8ba10c10b7dfba0417a3
4
- data.tar.gz: 051cd8132c24bb1e640171f747a25342f8b59d45
3
+ metadata.gz: 7d6b05b18971056f0854dc2b5674f8022bc3da6c
4
+ data.tar.gz: 4009d559fa7b8268f3f56c27767bb1e3b15d9b26
5
5
  SHA512:
6
- metadata.gz: 3b658635745828831f4fdb86a97e14eb3aaddca9a8fe606ad8ea3ce366f743de8e100350dc82e278fa3832d2464585dff1ffddc41c0ebb60984b3db8543ad6e9
7
- data.tar.gz: 4521c421e386868aee477c20a6f7a33a78d225304be6e8f894560963f2862d9fde61f8c3cd915555f5c7964b7888b68f9c38dde662c91143e5771d2c2b8b6837
6
+ metadata.gz: 6d281c8cc12e304d6da77a91c2a1b306aa08e4943f953f955c721bed6cee91fb0a7686600561770cf658307d77cb33486c57f2a33ce5902a148f621f9a4360b1
7
+ data.tar.gz: a44f3092a705a11583df6c651dedbb4006a6fc6d0a07cb93128e3c34a4ee3696ad8e27dbc73329ed815c184aab7bc830a08abc6e6fb22b0a869957949166ca3d
data/lib/htot_conv/cli.rb CHANGED
@@ -16,7 +16,7 @@ module HTOTConv
16
16
  end
17
17
  attr_accessor :options, :from_options, :to_options
18
18
 
19
- def define_options(opts)
19
+ def define_options(opts, io_filter=false)
20
20
  opts.banner = %q{Hierarchical-Tree Outline Text Converter}
21
21
  opts.define_head %q{Usage: htot_conv [options] [input] [output]}
22
22
  opts.separator %q{}
@@ -53,11 +53,31 @@ module HTOTConv
53
53
 
54
54
  opts.separator ""
55
55
  opts.separator "I/O Options:"
56
- define_sub_options(opts, HTOTConv::Parser, "from") do |key, v|
57
- @from_options[key] = v
56
+ if io_filter
57
+ define_sub_options_of(opts, HTOTConv::Parser, options[:from_type], "from") do |key, v|
58
+ @from_options[key] = v
59
+ end
60
+ define_sub_options_of(opts, HTOTConv::Generator, options[:to_type], "from") do |key, v|
61
+ @to_options[key] = v
62
+ end
63
+ else
64
+ define_sub_options(opts, HTOTConv::Parser, "from") do |key, v|
65
+ @from_options[key] = v
66
+ end
67
+ define_sub_options(opts, HTOTConv::Generator, "to") do |key, v|
68
+ @to_options[key] = v
69
+ end
58
70
  end
59
- define_sub_options(opts, HTOTConv::Generator, "to") do |key, v|
60
- @to_options[key] = v
71
+ end
72
+
73
+ private
74
+ def define_sub_options_of(opts, klass, type, prefix) # :yields: key, v
75
+ type_klass = klass.const_get(Rinne.camelize(type.to_s))
76
+ type_klass.option_help.each do |key,v|
77
+ long_option = "--#{prefix}-#{key.to_s.tr('_','-')}"
78
+ opts.on("#{long_option}=VAL", v[:pat], "For #{type}, #{v[:desc]}") do |v|
79
+ yield key, v
80
+ end
61
81
  end
62
82
  end
63
83
 
@@ -102,6 +122,17 @@ module HTOTConv
102
122
  OptionParser.new do |opts|
103
123
  script_opts.define_options(opts)
104
124
 
125
+ begin
126
+ opts.parse!(args.dup)
127
+ rescue OptionParser::ParseError => ex
128
+ $stderr << ex.message << "\n"
129
+ exit 1
130
+ end
131
+ end
132
+
133
+ OptionParser.new do |opts|
134
+ script_opts.define_options(opts, true)
135
+
105
136
  begin
106
137
  opts.parse!(args)
107
138
  rescue OptionParser::ParseError => ex
@@ -23,7 +23,9 @@ module HTOTConv
23
23
  ws.add_row([
24
24
  @data.key_header[0],
25
25
  *(HTOTConv::Util.pad_array([@data.value_header[0]], max_level)),
26
- *((@data.value_header.length <= 1)? [] : @data.value_header.last(@data.value_header.length - 1)),
26
+ *(HTOTConv::Util.pad_array(
27
+ (@data.value_header.length <= 1)? [] : @data.value_header.last(@data.value_header.length - 1),
28
+ [max_value_length - 1, 0].max)),
27
29
  ], :style => Axlsx::STYLE_THIN_BORDER)
28
30
  1.upto(max_level) do |col_idx|
29
31
  edges = [:top, :bottom]
@@ -37,8 +39,9 @@ module HTOTConv
37
39
  key_value_cell = Array.new(max_level + 1, nil)
38
40
  key_value_cell[item.level - 1] = item.key
39
41
  key_value_cell[item.level ] = item.value[0]
40
- rest_value_cell = (item.value.length <= 1)? [] :
41
- HTOTConv::Util.pad_array(item.value.last(item.value.length - 1), max_value_length - 1)
42
+ rest_value_cell = HTOTConv::Util.pad_array(
43
+ (item.value.length <= 1)? [] : item.value.last(item.value.length - 1),
44
+ [max_value_length - 1, 0].max)
42
45
 
43
46
  ws.add_row(key_value_cell.concat(rest_value_cell),
44
47
  :style => Axlsx::STYLE_THIN_BORDER)
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module HTOTConv
3
- VERSION = "0.3.0"
3
+ VERSION = "0.3.1"
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: htot_conv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - "@cat_in_136"
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-10-26 00:00:00.000000000 Z
11
+ date: 2017-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: axlsx