idata 0.1.10 → 0.1.11
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 +4 -4
- data/bin/iexport +11 -2
- data/bin/report.rb +89 -0
- data/lib/idata/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ab3542577ca230ddea255512ff99872d02f1eb8
|
4
|
+
data.tar.gz: f647930f643c3e214c0d4f24ed652017483e260e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5cb288fb721bf84e13d2e20a655525fb177f3f8126d473cca9bb102c0b8344a48fd6c57e72701144f7a1dc2dfdc57eafe9c7eb391c1b5b5cd9b4edddb33e0eca
|
7
|
+
data.tar.gz: ff09447fa764b4cc2d380b930402856b5194626c5c4a9a01dd00810a576caaa41eafd7ee86d4331ca03bd7f6443e0e13d51a1daeccc44fde0a1d93445cb5940d
|
data/bin/iexport
CHANGED
@@ -22,7 +22,7 @@ CSV_DEFAULT_QUOTE_CHAR = '"'
|
|
22
22
|
|
23
23
|
$options = {}
|
24
24
|
parser = OptionParser.new("", 24) do |opts|
|
25
|
-
opts.banner = "\nProgram: Data Exporter\nAuthor:
|
25
|
+
opts.banner = "\nProgram: Data Exporter\nAuthor: Nghi Pham\n\n"
|
26
26
|
|
27
27
|
opts.on("-f", "--format FORMAT", "Output file format") do |v|
|
28
28
|
$options[:format] = v
|
@@ -43,6 +43,10 @@ parser = OptionParser.new("", 24) do |opts|
|
|
43
43
|
opts.on("--quote-char CHAR", "Quote null values") do |v|
|
44
44
|
$options[:quote_char] = v
|
45
45
|
end
|
46
|
+
|
47
|
+
opts.on("--query QUERY", "Custom query") do |v|
|
48
|
+
$options[:query] = v
|
49
|
+
end
|
46
50
|
|
47
51
|
opts.on("--delim DELIMITER", "CSV delimiter") do |v|
|
48
52
|
$options[:delim] = v
|
@@ -198,7 +202,12 @@ class Product < ActiveRecord::Base
|
|
198
202
|
end
|
199
203
|
|
200
204
|
CSV.open($options[:output], "wb", :quote_char => $options[:quote_char], :col_sep => $options[:delim], :row_sep => $options[:linebreak], :force_quotes => $options[:quotes]) do |csv|
|
201
|
-
|
205
|
+
if $options[:query]
|
206
|
+
scope = Product.find_by_sql($options[:query])
|
207
|
+
else
|
208
|
+
scope = Product.select($options[:select]).where($options[:where])
|
209
|
+
end
|
210
|
+
|
202
211
|
first = scope.first
|
203
212
|
|
204
213
|
if first
|
data/bin/report.rb
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
# DATA LOADER
|
2
|
+
#
|
3
|
+
# @author Nghi Pham
|
4
|
+
# @date April 2014
|
5
|
+
#
|
6
|
+
# The script loads data from a fixed-width text file or a CSV file and fills in
|
7
|
+
# a corresponding table in the specified database
|
8
|
+
# Issue ruby load.rb --help for guideline/examples
|
9
|
+
#
|
10
|
+
require 'optparse'
|
11
|
+
require 'csv'
|
12
|
+
require 'spreadsheet'
|
13
|
+
require 'fileutils'
|
14
|
+
|
15
|
+
|
16
|
+
CSV_DEFAULT_DELIMITER = ','
|
17
|
+
CSV_DEFAULT_QUOTE = '"'
|
18
|
+
|
19
|
+
$options = {input: []}
|
20
|
+
parser = OptionParser.new("", 24) do |opts|
|
21
|
+
opts.banner = "\nProgram: Data Exporter\nAuthor: Nghi Pham\n\n"
|
22
|
+
|
23
|
+
opts.on("-o", "--output OUT.xls", "") do |v|
|
24
|
+
$options[:output] = v
|
25
|
+
end
|
26
|
+
|
27
|
+
opts.on("--i", "--input NAME|PATH", "") do |v|
|
28
|
+
$options[:input] << v
|
29
|
+
end
|
30
|
+
|
31
|
+
opts.on("--delim DELIMITER", "Field DELIMITER (for CSV format only - default to COMMA ',')") do |v|
|
32
|
+
$options[:delim] = v
|
33
|
+
end
|
34
|
+
|
35
|
+
opts.on("--quote QUOTE", "Default to '\"'") do |v|
|
36
|
+
$options[:quote] = v
|
37
|
+
end
|
38
|
+
|
39
|
+
opts.on_tail('--help', 'Displays this help') do
|
40
|
+
puts opts, ""
|
41
|
+
exit
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
begin
|
46
|
+
parser.parse!
|
47
|
+
rescue SystemExit => ex
|
48
|
+
exit
|
49
|
+
end
|
50
|
+
|
51
|
+
if $options[:input].empty?
|
52
|
+
puts "\nPlease specify input: -i\n\n"
|
53
|
+
exit
|
54
|
+
end
|
55
|
+
|
56
|
+
if $options[:output].nil?
|
57
|
+
puts "\nPlease specify output: -o\n\n"
|
58
|
+
exit
|
59
|
+
end
|
60
|
+
|
61
|
+
$options[:input].map!{|e|
|
62
|
+
{
|
63
|
+
name: e.split(":")[0].strip,
|
64
|
+
path: e.split(":")[1].strip
|
65
|
+
}
|
66
|
+
}
|
67
|
+
$options[:delim] ||= CSV_DEFAULT_DELIMITER
|
68
|
+
$options[:quote] ||= CSV_DEFAULT_QUOTE
|
69
|
+
|
70
|
+
book = Spreadsheet::Workbook.new
|
71
|
+
|
72
|
+
$options[:input].each do |e|
|
73
|
+
puts "Loading #{e[:name]}"
|
74
|
+
sheet = book.create_worksheet :name => e[:name]
|
75
|
+
CSV.read(e[:path], :col_sep => $options[:delim], :quote_char => $options[:quote]).each_with_index do |row, i|
|
76
|
+
sheet.row(i).replace(row)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
book.write $options[:output]
|
81
|
+
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
|
data/lib/idata/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: idata
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nghi Pham
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -90,6 +90,7 @@ files:
|
|
90
90
|
- bin/ipatch
|
91
91
|
- bin/isanitize
|
92
92
|
- bin/ivalidate
|
93
|
+
- bin/report.rb
|
93
94
|
- guideline/Guideline.docx
|
94
95
|
- idata.gemspec
|
95
96
|
- lib/idata.rb
|