dorian-sort-csv 0.0.3 → 1.0.0

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/bin/sort-csv +43 -6
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0fba7529fd591d2e421edd2af0bd88d9a099eecf0a34004f45093a3f58c6f020
4
- data.tar.gz: c1abea27d35e3e234040b0788d916b31c2f4ebac5192d3f2f0d43880a513a0f2
3
+ metadata.gz: 98659274796f85819874712d40a2a405a09413d3b6c0f80302e44db5643cea89
4
+ data.tar.gz: 62d3fba912ecc0c8c282e76ba1e197e805b2131556dac4ff57ed9b3d539e4b6f
5
5
  SHA512:
6
- metadata.gz: 30d640c34bfced3a6dc7b057bcb70a6b8dc7274222a3e4d655e562e5f9162818d81de619db4ffea073f8447065da262a58040ea1e78727b266f787322a113e02
7
- data.tar.gz: 05c2f2e62dcfbd9e5c389e0165c3df1e7bffed1dcca3f6cec183a9f83f51303e1f1b5ab0e67acf3c405d09615997df0194cf3eddc56019c73fb69d276a739bba
6
+ metadata.gz: 81262a1e9003184ec1f08ea31d6bbc9c2f9f7cdc61f392576344161a1ca374e0299c2b50af87910ba5aa6c73160b7d5ad5aaa8556dc0edc6de469a40854c0b7c
7
+ data.tar.gz: b820b97e7459224e71fd01699de047897b27f8a1caf5f677809a4c30322ee846f2b926beda1b1344c812c80ef607fa51b8f257de605c9450d337dfbcd9087c0e
data/bin/sort-csv CHANGED
@@ -1,12 +1,49 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- if ARGV.size != 1 || ARGV[0] == "--help" || ARGV[0] == "-h"
5
- puts "USAGE: ... | each CODE"
6
- exit
4
+ require "dorian/arguments"
5
+ require "csv"
6
+
7
+ parsed =
8
+ Dorian::Arguments.parse(
9
+ integers: {
10
+ alias: :i
11
+ },
12
+ headers: {
13
+ alias: :h
14
+ },
15
+ version: {
16
+ alias: :v
17
+ },
18
+ help: {
19
+ alias: :h
20
+ }
21
+ )
22
+
23
+ abort parsed.help if parsed.options.help
24
+
25
+ if parsed.options.version
26
+ abort File.read(File.expand_path("../../VERSION", __FILE__))
7
27
  end
8
28
 
9
- $stdin.each_line do |it|
10
- it.strip!
11
- eval(ARGV.first)
29
+ inputs = parsed.files.map { |file| File.read(file) }
30
+ inputs = [$stdin.each_line.to_a.map(&:strip).join("\n")] if inputs.empty?
31
+ headers = parsed.options.headers
32
+
33
+ keys = parsed.arguments.map { |key| key.to_i.to_s == key ? key.to_i : key }
34
+
35
+ inputs.each do |input|
36
+ input = CSV.parse(input, headers:)
37
+
38
+ rows =
39
+ input.sort_by do |row|
40
+ keys.map { |key| parsed.options.integers ? row[key].to_i : row[key] }
41
+ end
42
+
43
+ puts(
44
+ CSV.generate do |output|
45
+ output << input.headers if headers
46
+ rows.each { |row| output << row }
47
+ end
48
+ )
12
49
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dorian-sort-csv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 1.0.0
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-22 00:00:00.000000000 Z
11
+ date: 2024-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: csv