ss2json 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,20 +5,21 @@ class Ss2Json
5
5
  class Options < OptionParser
6
6
  attr_reader :options
7
7
  DEFAULT_OPTIONS = {
8
- :first_row => 1,
9
- :sheet => nil,
10
- :file => nil,
11
- :check_column => nil,
12
- :action => :convert,
13
- :orientation => :horizontal,
14
- :key_column => 1,
15
- :value_column => 2,
16
- :converter => {
17
- :show_null => false,
18
- :dont_convert => false,
19
- :ignored_values => [],
20
- :downcase_first_letter => true
21
- }
8
+ :first_row => 1,
9
+ :sheet => nil,
10
+ :file => nil,
11
+ :check_column => nil,
12
+ :action => :convert,
13
+ :orientation => :horizontal,
14
+ :key_column => 1,
15
+ :value_column => 2,
16
+ :converter => {
17
+ :show_null => false,
18
+ :dont_convert => false,
19
+ :ignored_values => [],
20
+ :downcase_first_letter => true,
21
+ :key_pattern => nil
22
+ }
22
23
 
23
24
  }
24
25
 
@@ -106,6 +107,10 @@ class Ss2Json
106
107
  @options[:converter][:downcase_first_letter] = false
107
108
  end
108
109
 
110
+ opts.on("--key-pattern PATTERN", "keys must match against PATTERN defaults to '\\A[\\.\\w]+\\z'") do |pattern|
111
+ @options[:converter][:key_pattern] = pattern
112
+ end
113
+
109
114
  opts.separator "\nFilter options:"
110
115
 
111
116
  opts.on("-c", "--check-column NAME", "Only output objects wich his property NAME is not in IGNORED VALUES") do |t|
@@ -113,6 +118,7 @@ class Ss2Json
113
118
  end
114
119
 
115
120
 
121
+
116
122
  opts.separator "\n"
117
123
 
118
124
  opts.on_tail("-h","--help", "Show this help") do
@@ -19,6 +19,7 @@ class Ss2Json
19
19
  protected
20
20
 
21
21
  def is_valid_key?(key)
22
+ return !(key =~ Regexp.new("/#{@options[:key_pattern]}/")) if @options[:key_pattern]
22
23
  super && ! (key =~ /^i\./i)
23
24
  end
24
25
 
@@ -1,3 +1,3 @@
1
1
  class Ss2Json
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
@@ -57,4 +57,16 @@ class Ss2Json::RowConverterTest < Test::Unit::TestCase
57
57
  new_hash = Ss2Json::RowConverter.new(initial_hash)
58
58
  assert_equal({"name" => {"i" => 5}}, new_hash)
59
59
  end
60
+
61
+ def test_it_applies_key_pattern
62
+ initial_hash = { "@name.i" => 5}
63
+ options = {:key_pattern => '\A[\.\w\-@]+\z'}
64
+
65
+ new_hash = Ss2Json::RowConverter.new(initial_hash, options)
66
+ assert_equal({"@name" => {"i" => 5}}, new_hash)
67
+
68
+ new_hash = Ss2Json::RowConverter.new(initial_hash)
69
+ assert_equal({}, new_hash)
70
+ end
71
+
60
72
  end
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: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 0
10
- version: 0.3.0
9
+ - 1
10
+ version: 0.3.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Guillermo A\xCC\x81lvarez"
@@ -15,8 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-06-04 00:00:00 +00:00
19
- default_executable:
18
+ date: 2012-11-29 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
21
  name: nested_hash
@@ -76,7 +75,6 @@ files:
76
75
  - test/ss2json (1).ods
77
76
  - test/ss2json.ods
78
77
  - test/ss2json.xls
79
- has_rdoc: true
80
78
  homepage: ""
81
79
  licenses: []
82
80
 
@@ -106,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
104
  requirements: []
107
105
 
108
106
  rubyforge_project: ss2json
109
- rubygems_version: 1.6.2
107
+ rubygems_version: 1.8.24
110
108
  signing_key:
111
109
  specification_version: 3
112
110
  summary: SpreadSheet to Json convert