cellar 0.1.6 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cellar.rb +24 -9
- 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: 9e474bc4dc354fe4c5fff6e2381e33e068ceb17a58fec95658ecd333ac7077bc
|
4
|
+
data.tar.gz: 540a05eaf9f6625240f4a27ccfd7956055466786ddf3e818a0c260e14a92eed0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ec873d0b0010c91e7b4bc0015b465a8866ae144aab223b6db5116c74a1e753cf9207713c9714eead2026c30d108883dfe1593812d0a197bf80ed7f35e0996db
|
7
|
+
data.tar.gz: 27f2fc1462e97b3613411a1129976cb963e5b77df810b1c914e2886c21e8aee3f9a39e27e71bc21744a30a3c95ef6db8c912d4b2a8a010d077528cbbeb6959f7
|
data/lib/cellar.rb
CHANGED
@@ -18,24 +18,28 @@ class Object
|
|
18
18
|
empty? or respond_to?(:strip) && strip.empty?
|
19
19
|
end unless defined? blank?
|
20
20
|
|
21
|
-
def if_blank
|
21
|
+
def if_blank(val)
|
22
22
|
blank? ? val : self
|
23
|
-
end unless defined? if_blank
|
23
|
+
end unless defined? if_blank
|
24
|
+
|
25
|
+
def if_present
|
26
|
+
blank? ? nil : self
|
27
|
+
end unless defined? if_present
|
24
28
|
end
|
25
29
|
|
26
30
|
class Cellar
|
27
|
-
VERSION="0.
|
31
|
+
VERSION="0.2.0"
|
28
32
|
|
29
33
|
attr_reader :fields
|
30
34
|
attr_reader :values
|
31
35
|
attr_accessor :strict
|
32
36
|
|
33
|
-
def initialize(obj=nil, header: true, strict: true)
|
37
|
+
def initialize(obj=nil, header: true, strict: true, index: nil)
|
34
38
|
@fields = []
|
35
39
|
@values = []
|
36
40
|
@finder = {}
|
37
41
|
@seeker = {}
|
38
|
-
@index =
|
42
|
+
@index = index
|
39
43
|
@widest = 0
|
40
44
|
|
41
45
|
if obj.is_a?(Array)
|
@@ -191,7 +195,7 @@ class Cellar
|
|
191
195
|
end
|
192
196
|
|
193
197
|
def cells
|
194
|
-
[@fields.dup] + @rows
|
198
|
+
[@fields.dup] + (@rows || [@values])
|
195
199
|
end
|
196
200
|
|
197
201
|
def rows
|
@@ -227,6 +231,18 @@ class Cellar
|
|
227
231
|
self
|
228
232
|
end
|
229
233
|
|
234
|
+
def fill!(data, &block)
|
235
|
+
self.class == data.class or raise "unable to fill with your #{data.class}"
|
236
|
+
data.values.each_with_index do |val, idx|
|
237
|
+
next if val.blank?
|
238
|
+
field = data.fields[idx]
|
239
|
+
index = index(field) || add_field(field)
|
240
|
+
value = @values[index]
|
241
|
+
@values[index] = block && !value.nil? ? block.call(value, val) : val
|
242
|
+
end
|
243
|
+
self
|
244
|
+
end
|
245
|
+
|
230
246
|
def index!(field=nil, &block)
|
231
247
|
@rows ||= []
|
232
248
|
@index = field || block or raise "index needs a field or a block"
|
@@ -242,8 +258,7 @@ class Cellar
|
|
242
258
|
end
|
243
259
|
|
244
260
|
def seek!(seek)
|
245
|
-
|
246
|
-
@seeker.empty? and raise "not indexed"
|
261
|
+
return nil if @rows.blank? || @seeker.blank?
|
247
262
|
|
248
263
|
if row = @seeker[seek]
|
249
264
|
row(row)
|
@@ -310,7 +325,7 @@ class Cellar
|
|
310
325
|
meth[pict % vals]
|
311
326
|
meth[line] if !tabs && ((seen += 1) == 0)
|
312
327
|
end
|
313
|
-
meth[line, "#{seen}
|
328
|
+
meth[line, "#{seen} row#{'s' if seen != 1} displayed", ""] unless tabs
|
314
329
|
self
|
315
330
|
end
|
316
331
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cellar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Shreeve
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-10-
|
11
|
+
date: 2024-10-19 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Ruby gem to deal with cells of data in rows and columns
|
14
14
|
email: steve.shreeve@gmail.com
|