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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 04a1f95d975d1d275d120e81fb1a3226e2d8ff93807ad70578e6ac1171c6d525
4
- data.tar.gz: 2f16578c4588470f8d4e5ad49971febf3a50201c6fd874b5986b65f53c85fcdb
3
+ metadata.gz: 9e6408da76c6f8072c649192adc66ad1cfa4c94eca8639b8b5aef4200f208a1f
4
+ data.tar.gz: 63df59dd87c321e33440ea9211fb39e6d9fd5c09e96e75ce10781ce7f9286cb5
5
5
  SHA512:
6
- metadata.gz: cd859cd9d54f2d689939786042943cd65a39ee476964e3d089bef9a5c9468fb3b508ad7fb335ad7e76899745ff19c172de2b302dfffd032521aecc449debd299
7
- data.tar.gz: 7d1a4acba85f7d6cb7197b6b7b98407b8c6280091a867017afc54fe4460fb43b04e138b407773c230ac7ff031e5dc60d09999030485e04aed7b80be81fd80e4f
6
+ metadata.gz: 25d8f2bdd0c3c7f8bc5dc5a22bbb07bde56db6f7a211ddae00595200001ae74e481d7cc50fe285745ef7d34c42f45c472a502438b698b0929c11caf0f028f1bc
7
+ data.tar.gz: 8a58b03cdfa6c49eecb68639c1de50ae37d1c2d711d823b7976ff838d3d1f0ad9a3e9a267a858e92db4c313027611bec3a134e8b2cd9aea8594e9281fbbabd32
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ * 0.22.1
2
+
3
+ - Rationnalisation de la méthode `CSV.foreach_backward` qui, maintenant, fonctionne plus
4
+ vite que `foreach` pour trouver un élément plus près de la fin.
5
+
1
6
  * 022.0
2
7
 
3
8
  - Extension pour la clas CSV (lecture en arrière)
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
 
@@ -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
- line = "#{header}\n#{line}\n" if options[:headers]
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
@@ -1,3 +1,3 @@
1
1
  module Clir
2
- VERSION = "0.22.0"
2
+ VERSION = "0.22.1"
3
3
  end
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.0
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: []