ss2json 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Changelog +5 -0
- data/lib/ss2json/cli.rb +31 -8
- data/lib/ss2json/options.rb +12 -2
- data/lib/ss2json/row_converter.rb +1 -1
- data/lib/ss2json/version.rb +1 -1
- metadata +5 -5
data/Changelog
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
2012-05-29 Guillermo Alvarez <guillermo@cientifico.net>
|
2
|
+
|
3
|
+
* cli.rb (process_horizontal): Support for generating hash output instead of
|
4
|
+
an array using one of the keys.
|
5
|
+
|
1
6
|
2012-05-24 Guillermo Alvarez <guillermo@cientifico.net>
|
2
7
|
|
3
8
|
* cli.rb (initi_document) : If you specify an invalid sheets, the message
|
data/lib/ss2json/cli.rb
CHANGED
@@ -38,6 +38,7 @@ class Ss2Json
|
|
38
38
|
@doc.sheets.join("\n")
|
39
39
|
else
|
40
40
|
if options[:orientation] == :horizontal
|
41
|
+
@options[:first_row] += 1
|
41
42
|
process_horizontal
|
42
43
|
elsif options[:orientation] == :vertical
|
43
44
|
process_vertical
|
@@ -61,20 +62,42 @@ class Ss2Json
|
|
61
62
|
end
|
62
63
|
|
63
64
|
def process_horizontal
|
64
|
-
@
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
65
|
+
if @options[:hash_key]
|
66
|
+
@content = {}
|
67
|
+
each_hash_row do |hash|
|
68
|
+
if value = hash.get(@options[:hash_key])
|
69
|
+
hash.delete(@options[:hash_key]) unless @options[:dont_remove_key]
|
70
|
+
@content[value] = hash
|
71
|
+
end
|
70
72
|
end
|
71
|
-
|
73
|
+
|
74
|
+
else
|
75
|
+
@content = []
|
76
|
+
each_hash_row do |hash|
|
77
|
+
@options[:hash_key]
|
78
|
+
@content << hash
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def each_row
|
84
|
+
(@options[:first_row]).upto(@doc.last_row).each do |row_n|
|
85
|
+
yield row_n
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def each_hash_row
|
90
|
+
each_row do |row|
|
91
|
+
row = @doc.find(row)[0]
|
92
|
+
object = RowConverter.new(row,@options[:converter])
|
93
|
+
next if @options[:check_column] && object[@options[:check_column]].nil?
|
94
|
+
yield object
|
72
95
|
end
|
73
96
|
end
|
74
97
|
|
75
98
|
def process_vertical
|
76
99
|
hash = {}
|
77
|
-
|
100
|
+
each_row do |row|
|
78
101
|
key = @doc.cell(row, @options[:key_column])
|
79
102
|
value = @doc.cell(row, @options[:value_column])
|
80
103
|
hash[key] = value
|
data/lib/ss2json/options.rb
CHANGED
@@ -66,14 +66,24 @@ class Ss2Json
|
|
66
66
|
@options[:first_row] = row.to_i
|
67
67
|
end
|
68
68
|
|
69
|
+
opts.separator "\nHorizontal mode options:"
|
70
|
+
|
71
|
+
opts.on("-u", "--use-key KEY", "Generate a hash instead of an array using KEY as the hash index key") do |key|
|
72
|
+
@options[:hash_key] = key
|
73
|
+
end
|
74
|
+
|
75
|
+
opts.on("--dont-remove-key", "Don't remove key from the hash") do
|
76
|
+
@options[:dont_remove_key] = true
|
77
|
+
end
|
78
|
+
|
69
79
|
opts.separator "\nVertical mode options:"
|
70
80
|
|
71
|
-
opts.on("-k", "--key-column", "Column where the keys are (Default to 1)") do |column|
|
81
|
+
opts.on("-k", "--key-column COLUMN_NUMBER", "Column where the keys are (Default to 1)") do |column|
|
72
82
|
die("Can't understand the column #{column}. Use a number") unless column =~ /\A\d*\z/
|
73
83
|
@options[:key_column] = column.to_i
|
74
84
|
end
|
75
85
|
|
76
|
-
opts.on("-a", "--value-column", "Column where the values are (Default to 2)") do |column|
|
86
|
+
opts.on("-a", "--value-column COLUMN_NUMBER", "Column where the values are (Default to 2)") do |column|
|
77
87
|
die("Can't understand the column #{column}. Use a number") unless column =~ /\A\d*\z/
|
78
88
|
@options[:value_column] = column.to_i
|
79
89
|
end
|
data/lib/ss2json/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ss2json
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- "Guillermo A\xCC\x81lvarez"
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-05-
|
18
|
+
date: 2012-05-29 00:00:00 +00:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|