clir 0.22.0 → 0.22.1
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/CHANGELOG.md +5 -0
- data/clir.gemspec +1 -2
- data/lib/clir/CSV_extension.rb +36 -15
- data/lib/clir/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e6408da76c6f8072c649192adc66ad1cfa4c94eca8639b8b5aef4200f208a1f
|
4
|
+
data.tar.gz: 63df59dd87c321e33440ea9211fb39e6d9fd5c09e96e75ce10781ce7f9286cb5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 25d8f2bdd0c3c7f8bc5dc5a22bbb07bde56db6f7a211ddae00595200001ae74e481d7cc50fe285745ef7d34c42f45c472a502438b698b0929c11caf0f028f1bc
|
7
|
+
data.tar.gz: 8a58b03cdfa6c49eecb68639c1de50ae37d1c2d711d823b7976ff838d3d1f0ad9a3e9a267a858e92db4c313027611bec3a134e8b2cd9aea8594e9281fbbabd32
|
data/CHANGELOG.md
CHANGED
data/clir.gemspec
CHANGED
@@ -7,8 +7,7 @@ Gem::Specification.new do |s|
|
|
7
7
|
s.email = ["philippe.perret@yahoo.fr"]
|
8
8
|
|
9
9
|
s.summary = %q{Command Line Interface for Ruby applications}
|
10
|
-
s.description = %q{Command Line Interface for Ruby applications}
|
11
|
-
# s.homepage = "https://github.com/PhilippePerret/clir"
|
10
|
+
s.description = %q{Command Line Interface for Ruby applications, a lot of usefull methods}
|
12
11
|
s.homepage = "https://rubygems.org/gems/clir"
|
13
12
|
s.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
14
13
|
|
data/lib/clir/CSV_extension.rb
CHANGED
@@ -26,6 +26,7 @@ class << self
|
|
26
26
|
def readlines_backward(path, **options, &block)
|
27
27
|
|
28
28
|
options ||= {}
|
29
|
+
options.key?(:col_sep) || options.merge!(col_sep: ',')
|
29
30
|
|
30
31
|
file = File.new(path)
|
31
32
|
size = File.size(file)
|
@@ -37,7 +38,9 @@ class << self
|
|
37
38
|
#
|
38
39
|
# Si options[:headers] est true, il faut récupérer la première
|
39
40
|
# ligne et la transformer en entête
|
41
|
+
# @note Cet entête permettra d'instancier les rangées (\CSV::Row)
|
40
42
|
#
|
43
|
+
headers = nil
|
41
44
|
if options[:headers]
|
42
45
|
begin
|
43
46
|
fileh = File.open(path,'r')
|
@@ -53,13 +56,6 @@ class << self
|
|
53
56
|
|
54
57
|
if block_given?
|
55
58
|
#
|
56
|
-
# Les options pour CSV.parse
|
57
|
-
# On garde seulement les convertisseurs de données et on met
|
58
|
-
# toujours headers à false (puisque c'est seulement la ligne
|
59
|
-
# de données qui sera parser)
|
60
|
-
#
|
61
|
-
# line_csv_options = {headers:false, converters: options[:converters]}
|
62
|
-
line_csv_options = options
|
63
59
|
#
|
64
60
|
# Avec un bloc fourni, on va lire ligne par ligne en partant
|
65
61
|
# de la fin.
|
@@ -79,11 +75,6 @@ class << self
|
|
79
75
|
#
|
80
76
|
# On boucle tant qu'on n'interrompt pas (pour le moment)
|
81
77
|
#
|
82
|
-
# QUESTIONS
|
83
|
-
# 1. Comment repère-t-on la fin ? En comparant la position
|
84
|
-
# actuelle du pointeur avec 0 ?
|
85
|
-
# 2. Comment met-on fin à la recherche (c'est presque la
|
86
|
-
# même question)
|
87
78
|
while true
|
88
79
|
#
|
89
80
|
# On lit la longueur du tampon en l'ajoutant à ce qu'on a
|
@@ -115,11 +106,41 @@ class << self
|
|
115
106
|
#
|
116
107
|
lines.each do |line|
|
117
108
|
line = line.chomp
|
118
|
-
|
109
|
+
|
110
|
+
# Je crois que c'est ça qui prend trop de temps
|
111
|
+
# line = "#{header}\n#{line}\n" if options[:headers]
|
119
112
|
# puts "line parsée : #{line.inspect}".bleu
|
120
|
-
line_csv = CSV.parse(line, **line_csv_options)
|
113
|
+
# line_csv = CSV.parse(line, **line_csv_options)
|
121
114
|
# puts "line_csv: #{line_csv.inspect}::#{line_csv.class}".orange
|
122
|
-
yield line_csv[0]
|
115
|
+
# yield line_csv[0]
|
116
|
+
#
|
117
|
+
|
118
|
+
#
|
119
|
+
# Convertir les valeurs si des convertisseurs sont
|
120
|
+
# définis
|
121
|
+
# NOTE : Pour le moment, je reste simple et un peu brut
|
122
|
+
#
|
123
|
+
values = line.split(options[:col_sep])
|
124
|
+
if options[:converters]
|
125
|
+
values = values.collect do |value|
|
126
|
+
options[:converters].each do |converter|
|
127
|
+
if converter == :numeric && value.numeric?
|
128
|
+
value = value.to_i and break
|
129
|
+
elsif converter == :date && value.match?(/[0-9]{2,4}/)
|
130
|
+
begin
|
131
|
+
value = Date.parse(value)
|
132
|
+
break
|
133
|
+
rescue nil
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
value
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
row = CSV::Row.new(headers, values)
|
142
|
+
|
143
|
+
yield row
|
123
144
|
end
|
124
145
|
end
|
125
146
|
#
|
data/lib/clir/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clir
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.22.
|
4
|
+
version: 0.22.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Philippe Perret
|
@@ -66,7 +66,7 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
-
description: Command Line Interface for Ruby applications
|
69
|
+
description: Command Line Interface for Ruby applications, a lot of usefull methods
|
70
70
|
email:
|
71
71
|
- philippe.perret@yahoo.fr
|
72
72
|
executables: []
|