csv-query 0.1.7 → 0.1.8
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/Gemfile.lock +1 -1
- data/Makefile +3 -0
- data/lib/csv/query/version.rb +1 -1
- data/lib/csv/query.rb +16 -6
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 10e0753855ecc08fcd04cc4d16fce8b8d0aa9aa6113faeee99a6cb001f3767ca
|
4
|
+
data.tar.gz: 9f401840f83d8644f0294f5d5981a3709203d46ed673dc9b0a07076b34f047ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e053344687d0998203130842f8ed356d6ba86c800e4399d6de97b3bcaa8e1d12ccadcb33e50cf9d9f33cd78f6f6ebe88333113208e1cdc81be213ec7b1b6ada8
|
7
|
+
data.tar.gz: b5c6a24d6c36b907f5a6f71b7d930bdf2854e6346255cee30da1dfca3c09b45ffd655c742422b98d9e89cb660814d8cb7059ae493f8c4ea9549fe96770908ff4
|
data/Gemfile.lock
CHANGED
data/Makefile
ADDED
data/lib/csv/query/version.rb
CHANGED
data/lib/csv/query.rb
CHANGED
@@ -12,10 +12,10 @@ module Csv
|
|
12
12
|
module Query
|
13
13
|
# Your code goes here...
|
14
14
|
def self.run!
|
15
|
-
file_path, query =
|
16
|
-
ARGV.getopts(nil, 'file:', 'query:').values
|
15
|
+
file_path, query, json =
|
16
|
+
ARGV.getopts(nil, 'file:', 'query:', 'json').values
|
17
17
|
|
18
|
-
InMemoryAR.new(file_path).run! {
|
18
|
+
InMemoryAR.new(file_path, json).run! {
|
19
19
|
# InMemoryAR::Record.all
|
20
20
|
eval(query)
|
21
21
|
}
|
@@ -52,7 +52,8 @@ module Csv
|
|
52
52
|
|
53
53
|
attr_reader :file_path
|
54
54
|
|
55
|
-
def initialize
|
55
|
+
def initialize(file_path, json)
|
56
|
+
@json = json
|
56
57
|
@file_path = file_path
|
57
58
|
|
58
59
|
migration(csv_headers)
|
@@ -72,13 +73,22 @@ module Csv
|
|
72
73
|
end
|
73
74
|
end
|
74
75
|
|
76
|
+
def json_format?
|
77
|
+
@json
|
78
|
+
end
|
79
|
+
|
75
80
|
def run!
|
76
81
|
csv.each do |row|
|
77
82
|
Record.create!(row.to_h)
|
78
83
|
end
|
79
84
|
records = yield
|
80
|
-
|
81
|
-
|
85
|
+
|
86
|
+
if json_format?
|
87
|
+
puts records.map { |e| e.attributes }.to_json
|
88
|
+
else
|
89
|
+
rows = records.map { |e| e.attributes.values }
|
90
|
+
puts Terminal::Table.new :headings => csv_headers, :rows => rows
|
91
|
+
end
|
82
92
|
end
|
83
93
|
end
|
84
94
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: csv-query
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- naofumi-fujii
|
@@ -124,6 +124,7 @@ files:
|
|
124
124
|
- Gemfile
|
125
125
|
- Gemfile.lock
|
126
126
|
- LICENSE.txt
|
127
|
+
- Makefile
|
127
128
|
- README.md
|
128
129
|
- Rakefile
|
129
130
|
- bin/console
|