csv_to_products 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 44adfd2ab614840adf26ae2a4b077e7b97fcc49a
4
- data.tar.gz: c3c41c0c39004fad4482796199565f78a2d48c45
3
+ metadata.gz: 768a83ed10a3a99abbe78a1bb85b5b8cdc218c6b
4
+ data.tar.gz: 1823c0c5bf2272bbbf720a63b42c1706462b7f71
5
5
  SHA512:
6
- metadata.gz: 4db7720d3c89e0c7b9d1e99bf23363add78cafdecbe9df57edd5697202833384ad27ba285a3f12d53a2c4569d35dfd859d9118afa840b85297bf687ba1adfdc2
7
- data.tar.gz: 19b4f7e5c0535866cfb6b3699b498066d85ebe5333730b432217e08fc64ab8fdfc4613519d97c86a9d4c50bd56cf56e8e078549c863a7b725cf8c511c312aceb
6
+ metadata.gz: 18bc1aafef88c5455961d501cfa2ab4af55e1236152bdca0a2d412660328e17510a28a00bde725bf3f3a5d5d296dca02160b5c1c443e61c045c1ee38174d0f36
7
+ data.tar.gz: eed9c3483e8f71258a80918620611a5f5245fc35ad28a21e6f885bcbd08f5b0a5a9f80c53eff38ca7a1d6723bb8fc9b9dd5711ca5d1c4b3763b1e8b59b44244a
@@ -49,7 +49,7 @@ module CSVToProducts
49
49
  end
50
50
 
51
51
  def sanitize(s)
52
- s.to_s.gsub(/[ \/\\]/, '-').gsub(/[^0-9A-Za-z\-]/, '').downcase
52
+ s.to_s.gsub(/[ \/\\]/, '-').gsub(/[^\w\-]/, '').downcase
53
53
  end
54
54
 
55
55
  def is_number?(s)
data/lib/pairs.rb CHANGED
@@ -6,7 +6,7 @@ module Pairs
6
6
  row.each do |k, v|
7
7
  d_k = dehumanize(k)
8
8
  next if d_k == 'description'
9
- next pairs[d_k] = v unless k.include?('[')
9
+ next pairs[d_k] = quote_dangerous(v) unless k.include?('[')
10
10
  next unless affirmative?(v)
11
11
  add_to_array(k, v)
12
12
  end
@@ -25,11 +25,12 @@ module Pairs
25
25
  def add_to_array(k, v)
26
26
  k, v = k.scan(/[^\[\]]+/)
27
27
  pairs[k] ||= []
28
- pairs[k] << v
28
+ pairs[k] << quote_dangerous(v)
29
29
  end
30
30
 
31
31
  def pretty_pairs
32
32
  pairs.map do |k, v|
33
+ next unless v && v.length > 0
33
34
  v = "[#{v.join(', ')}]" if v.is_a?(Array)
34
35
  "#{k}: #{v}\n"
35
36
  end.join
@@ -38,5 +39,10 @@ module Pairs
38
39
  def dehumanize(s)
39
40
  s.to_s.gsub(' ', '_').downcase
40
41
  end
42
+
43
+ def quote_dangerous(s)
44
+ return s unless s =~ /[^\w. ]/
45
+ s =~ /'/ ? "\"#{s}\"" : "'#{s}'"
46
+ end
41
47
  end
42
48
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: csv_to_products
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max White
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-29 00:00:00.000000000 Z
11
+ date: 2015-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -57,7 +57,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
57
57
  version: '0'
58
58
  requirements: []
59
59
  rubyforge_project:
60
- rubygems_version: 2.4.5
60
+ rubygems_version: 2.2.2
61
61
  signing_key:
62
62
  specification_version: 4
63
63
  summary: Jekyll-Store cmdline tool to translate CSV file to products.