distributator 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/distributator.rb +102 -0
- metadata +46 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 195efa159af191ca6c0d5c73a3484f9e8d660869
|
4
|
+
data.tar.gz: f7e06af0cea51d7390eb70cb755cd03c06914af5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e9be8c96d04d75e3bb6caba64ba6bdb53417071814722417cd5ff13911a81d05d20dc80f3ab0d6389ee9ecfe9f2157e236e537b9e1a00be20e352d0d6bcf894b
|
7
|
+
data.tar.gz: 5b6f4234a34126e4a055c86ee9c319d5a5dbe58a33103031c777d5f83802d56c6a1a8b2b7c5f4c03722747f22b3d69ab82060ec70c5f1cfde54795e6e815b21a
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require 'csv'
|
2
|
+
require 'active_support/inflector'
|
3
|
+
require 'date'
|
4
|
+
|
5
|
+
#################################################
|
6
|
+
# REMINDER: An empty cell can return nil or '' #
|
7
|
+
#################################################
|
8
|
+
|
9
|
+
class Distributator < CSV
|
10
|
+
def initialize(data, options = Hash.new)
|
11
|
+
options.merge!({ headers: true,
|
12
|
+
header_converters: [self.class.rename_header,
|
13
|
+
*options[:header_converters]] })
|
14
|
+
super(data, options)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.rename_header
|
18
|
+
->(header) do
|
19
|
+
case header
|
20
|
+
when /\A['"]?estimated_availability_date['"]?\Z/i
|
21
|
+
'available_on'
|
22
|
+
when /\A['"]?image_(\w+)_(\d+)['"]?\Z/
|
23
|
+
# TODO: should this have a default value?
|
24
|
+
lookup = { 'reference' => 'url', 'name' => 'title' }
|
25
|
+
"images.#{$2}.#{lookup[$1]}"
|
26
|
+
when /\A['"]?upc['"]?\Z/i
|
27
|
+
'id'
|
28
|
+
when /\A['"]?cost['"]?\Z/i
|
29
|
+
'cost_price'
|
30
|
+
when /\A['"]?product_title['"]?\Z/i
|
31
|
+
'name'
|
32
|
+
else
|
33
|
+
header.gsub(/'|"/, '')
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
module DSCO_Table
|
40
|
+
class DSCOError < StandardError; end
|
41
|
+
class PriceError < DSCOError; end
|
42
|
+
|
43
|
+
def convert_attributes
|
44
|
+
each do |row|
|
45
|
+
attr_indices.each do |index|
|
46
|
+
attr_name = "attribute_name_#{index}"
|
47
|
+
attr_val = "attribute_value_#{index}"
|
48
|
+
row["properties.#{row[attr_name]}"] = row[attr_val]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
attr_indices.each do |index|
|
53
|
+
delete("attribute_name_#{index}")
|
54
|
+
delete("attribute_value_#{index}")
|
55
|
+
end; return nil
|
56
|
+
end
|
57
|
+
|
58
|
+
def convert_price
|
59
|
+
each do |row|
|
60
|
+
map, msrp = row['map'], row['msrp']
|
61
|
+
|
62
|
+
price = map unless map.nil? || map.to_f.zero? # implies #empty?
|
63
|
+
price ||= msrp
|
64
|
+
raise PriceError if price.to_f.zero?
|
65
|
+
row['price'] = price
|
66
|
+
end
|
67
|
+
|
68
|
+
delete('msrp'); delete('map')
|
69
|
+
end
|
70
|
+
|
71
|
+
def convert_taxons
|
72
|
+
each do |row|
|
73
|
+
row['category'].split('|').each_with_index do |taxon, i|
|
74
|
+
# WARNING: Jenson only uses one taxon group per product
|
75
|
+
# So this code only handles one taxon group.
|
76
|
+
row["taxons.0.#{i}"] = taxon
|
77
|
+
end
|
78
|
+
end
|
79
|
+
delete('category')
|
80
|
+
end
|
81
|
+
|
82
|
+
def make_permalinks
|
83
|
+
each do |row|
|
84
|
+
row['permalink'] = row['name'].parameterize
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def normalize_available_on
|
89
|
+
each do |row|
|
90
|
+
if row['available_on'].nil? || row['available_on'].empty?
|
91
|
+
row['available_on'] = DateTime.now.iso8601
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
private
|
97
|
+
def attr_indices
|
98
|
+
headers.map { |h| h.match(/attribute_name_(\d+)/); $1 }.compact
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
CSV::Table.include DSCO_Table
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: distributator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Cooper Lebrun
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-11-26 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Tools for converting a DSCO distributor's product CSV into the Wombat
|
14
|
+
product format CSV for uploading. WORK IN PROGRESS.
|
15
|
+
email: cooperlebrun@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/distributator.rb
|
21
|
+
homepage: http://rubygems.org/gems/distributator
|
22
|
+
licenses:
|
23
|
+
- MIT
|
24
|
+
metadata: {}
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubyforge_project:
|
41
|
+
rubygems_version: 2.4.5.1
|
42
|
+
signing_key:
|
43
|
+
specification_version: 4
|
44
|
+
summary: Convert DSCO CSVs to Wombat/Spree format!
|
45
|
+
test_files: []
|
46
|
+
has_rdoc:
|