csv-query 0.1.15 → 0.1.16
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/lib/csv/query.rb +14 -6
- data/lib/csv/query/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 81ed069b8d621a0f2b417b723427518730e34172fced51d716c35840d6632f2d
|
|
4
|
+
data.tar.gz: 1d9a05eee111aece4a15637643d51433cd7178a6447c2848eac3353fe5cf928d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1f1e68ad18f62b75b53fae391a676ba045829044efee4acc70e699e5cc5b6659500a67471c91f575847c2556a85a7bae97f30dfc1d8994eb3a20d11accfcbdf4
|
|
7
|
+
data.tar.gz: 890b54e8f653aeefd08b8bfc262202b932ff398a2c6dbb790a7aa0d753dfafc2095de3eb5229e00fe5a0f5b7307546ffb8c77d011174c16897663eeffe79e9b6
|
data/Gemfile.lock
CHANGED
data/lib/csv/query.rb
CHANGED
|
@@ -11,10 +11,11 @@ module Csv
|
|
|
11
11
|
class CLI < Thor
|
|
12
12
|
# Your code goes here...
|
|
13
13
|
method_option :file, type: :string, required: true
|
|
14
|
+
method_option :sql, type: :string
|
|
14
15
|
method_option :json
|
|
15
16
|
desc "main", "do something"
|
|
16
17
|
def main
|
|
17
|
-
InMemoryAR.new(options[:file], options[:json]).run!
|
|
18
|
+
InMemoryAR.new(options[:file], options[:json], options[:sql]).run!
|
|
18
19
|
end
|
|
19
20
|
default_task :main
|
|
20
21
|
|
|
@@ -58,9 +59,10 @@ module Csv
|
|
|
58
59
|
csv.headers
|
|
59
60
|
end
|
|
60
61
|
|
|
61
|
-
attr_reader :file_path
|
|
62
|
+
attr_reader :file_path, :json, :sql
|
|
62
63
|
|
|
63
|
-
def initialize(file_path, json)
|
|
64
|
+
def initialize(file_path, json, sql)
|
|
65
|
+
@sql = sql
|
|
64
66
|
@json = json
|
|
65
67
|
@file_path = file_path
|
|
66
68
|
|
|
@@ -82,7 +84,7 @@ module Csv
|
|
|
82
84
|
end
|
|
83
85
|
|
|
84
86
|
def json_format?
|
|
85
|
-
|
|
87
|
+
json
|
|
86
88
|
end
|
|
87
89
|
|
|
88
90
|
def run!
|
|
@@ -90,11 +92,17 @@ module Csv
|
|
|
90
92
|
Record.create!(row.to_h)
|
|
91
93
|
end
|
|
92
94
|
|
|
93
|
-
records = InMemoryAR::Record.all
|
|
94
|
-
|
|
95
95
|
render(records)
|
|
96
96
|
end
|
|
97
97
|
|
|
98
|
+
def records
|
|
99
|
+
if sql.present?
|
|
100
|
+
InMemoryAR::Record.find_by_sql(sql)
|
|
101
|
+
else
|
|
102
|
+
InMemoryAR::Record.all
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
98
106
|
def render records
|
|
99
107
|
if json_format?
|
|
100
108
|
puts Array.wrap(records).map { |e| e.to_h }.to_json
|
data/lib/csv/query/version.rb
CHANGED