dorian-csv-all 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/bin/csv-all +27 -7
  3. metadata +18 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 858bed804d85030475b691b4c9b9165fd6c4d5ce4d42a70c8f1cb2ba0cb87f1b
4
- data.tar.gz: 2fdf2f8ccac8ea010af83472d6d14e10230942eaa3238e4f5dd8ae068f3b58b6
3
+ metadata.gz: 4adb4f4705be9832ccbcff22a1d86c76eba159d3438ad101f425cbf90b49e952
4
+ data.tar.gz: cd01aec7691c409cc1b8c63fed9fd48f06b7d9ba81190fa9bc903ea223de0bcc
5
5
  SHA512:
6
- metadata.gz: a0e51348629b647e35cacd43676401e0a3366f0e44579c3ae68d49c810ddbaed57f4f8fb8ca030683a3f722abcd16f7a5d864904992a3f696d72cc3752e743ad
7
- data.tar.gz: 2a1b588ea78c12d72b58d547d99b8488fde41a6d0b91282ee0549ffab5f834c5f346a80cb84ae29eaca75c945c08a3351d8b11dedadaf4c88905cf2f430de148
6
+ metadata.gz: 4aba6d20dc5cb12c2a089e6bdf5b886b9eb8e7b319762755589c1e0db12b1d63fa57f1ee31612de8e7707fafa61e14f36490c5ca7be88498418fd50a724f37eb
7
+ data.tar.gz: 04cec9c1d410521d977f431deaf7a2f68dfbc0596d8f6d97a7dd0bf4719e7121680c276ed09b0cbd3e3d30668744f216e42940f09b255df6849616484d27fb21
data/bin/csv-all CHANGED
@@ -2,13 +2,33 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require "csv"
5
- require "dorian-to_struct"
5
+ require "dorian/to_struct"
6
+ require "dorian/arguments"
6
7
 
7
- HEADERS = ARGV.detect { |argv| argv == "-h" || argv == "--headers" }
8
+ parsed =
9
+ Dorian::Arguments.parse(
10
+ headers: :boolean,
11
+ version: {
12
+ alias: :v
13
+ },
14
+ help: {
15
+ alias: :h
16
+ }
17
+ )
8
18
 
9
- it =
10
- CSV
11
- .parse($stdin.each_line.to_a.map(&:strip).join("\n"), headers: !!HEADERS)
12
- .map { |line| HEADERS ? line.to_h.to_struct : line.to_a }
19
+ abort parsed.help if parsed.options.help
13
20
 
14
- eval((ARGV - [HEADERS]).join(" "))
21
+ if parsed.options.version
22
+ abort File.read(File.expand_path("../../VERSION", __FILE__))
23
+ end
24
+
25
+ inputs = parsed.files.map { |file| File.read(file) }
26
+ inputs = [$stdin.each_line.to_a.map(&:strip).join("\n")] if inputs.empty?
27
+ headers = parsed.options.headers
28
+
29
+ inputs.each do |input|
30
+ it = CSV.parse(input, headers:)
31
+ it = it.map { |line| headers ? line.to_h.to_struct : line.to_a }
32
+
33
+ eval(parsed.arguments.join(" "))
34
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dorian-csv-all
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dorian Marié
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-08-17 00:00:00.000000000 Z
11
+ date: 2024-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: csv
@@ -38,10 +38,21 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- description: |-
42
- Evaluates some code all lines of the csv input
43
-
44
- e.g. `cat users.csv | csv-all --headers "puts it.first[:name]"`
41
+ - !ruby/object:Gem::Dependency
42
+ name: dorian-arguments
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: evaluates some ruby code on all lines of the csv input
45
56
  email: dorian@dorianmarie.com
46
57
  executables:
47
58
  - csv-all
@@ -72,5 +83,5 @@ requirements: []
72
83
  rubygems_version: 3.5.11
73
84
  signing_key:
74
85
  specification_version: 4
75
- summary: Evaluates some code all lines of the csv input
86
+ summary: evaluates some ruby code on all lines of the csv input
76
87
  test_files: []