bmg 0.18.13 → 0.18.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bmg/reader/excel.rb +43 -28
- data/lib/bmg/relation/materialized.rb +3 -2
- data/lib/bmg/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8541ab1e17726eb751772cc29a3d198f8bc021d7
|
4
|
+
data.tar.gz: a4e07beb7b994d3ac6dda214e3a75822a1a3eb07
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '063179c6a79505b6baaaf800f56a35dc7084b95ac4fa2c73acc92e809bb1d164d99bb3ce6120863d3b87886f8e21b3bc3579a1043e01dc2938ff6c278a4c08c3'
|
7
|
+
data.tar.gz: 3fe57b85503565d547522f4a41ad608ca3839add2305e5108b212f269a4d76adb4d681da58cca01bea564c1ce24b70922215923f3df332d5a7d51dadc09a2ee8
|
data/lib/bmg/reader/excel.rb
CHANGED
@@ -10,32 +10,27 @@ module Bmg
|
|
10
10
|
}
|
11
11
|
|
12
12
|
def initialize(type, path, options = {})
|
13
|
-
|
13
|
+
require 'roo'
|
14
14
|
@path = path
|
15
15
|
@options = DEFAULT_OPTIONS.merge(options)
|
16
|
+
@type = type.knows_attrlist? ? type : type.with_attrlist(infer_attrlist)
|
16
17
|
end
|
17
18
|
|
18
19
|
def each
|
19
20
|
return to_enum unless block_given?
|
20
|
-
|
21
|
-
|
22
|
-
headers =
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
.
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
.each_with_object(init){|i,t|
|
34
|
-
t[headers[i]] = row[i]
|
35
|
-
}
|
36
|
-
yield(tuple)
|
37
|
-
end
|
38
|
-
end
|
21
|
+
|
22
|
+
headers = type.attrlist
|
23
|
+
headers = headers[1..-1] if generate_row_num?
|
24
|
+
start_at = @options[:skip] + 2
|
25
|
+
end_at = spreadsheet.last_row
|
26
|
+
(start_at..end_at).each do |i|
|
27
|
+
row = spreadsheet.row(i)
|
28
|
+
init = init_tuple(i - start_at + 1)
|
29
|
+
tuple = (0...headers.size).each_with_object(init){|i,t|
|
30
|
+
t[headers[i]] = row[i]
|
31
|
+
}
|
32
|
+
yield(tuple)
|
33
|
+
end
|
39
34
|
end
|
40
35
|
|
41
36
|
def to_ast
|
@@ -49,17 +44,37 @@ module Bmg
|
|
49
44
|
|
50
45
|
private
|
51
46
|
|
52
|
-
def
|
47
|
+
def spreadsheet
|
48
|
+
@spreadsheet ||= Roo::Spreadsheet
|
49
|
+
.open(@path, @options)
|
50
|
+
.sheet(@options[:sheet])
|
51
|
+
end
|
52
|
+
|
53
|
+
def infer_attrlist
|
54
|
+
row = spreadsheet.row(1+@options[:skip])
|
55
|
+
attrlist = row.map{|c| c.to_s.strip.to_sym }
|
56
|
+
attrlist.unshift(row_num_name) if generate_row_num?
|
57
|
+
attrlist
|
58
|
+
end
|
59
|
+
|
60
|
+
def generate_row_num?
|
61
|
+
!!@options[:row_num]
|
62
|
+
end
|
63
|
+
|
64
|
+
def row_num_name
|
53
65
|
case as = @options[:row_num]
|
54
|
-
when TrueClass
|
55
|
-
|
56
|
-
|
57
|
-
{}
|
58
|
-
when Symbol
|
59
|
-
{ :"#{as}" => i }
|
66
|
+
when TrueClass then :row_num
|
67
|
+
when Symbol then as
|
68
|
+
else nil
|
60
69
|
end
|
61
70
|
end
|
62
71
|
|
72
|
+
def init_tuple(i)
|
73
|
+
return {} unless generate_row_num?
|
74
|
+
|
75
|
+
{ row_num_name => i }
|
76
|
+
end
|
77
|
+
|
63
78
|
end # class Excel
|
64
79
|
end # module Reader
|
65
|
-
end # module Bmg
|
80
|
+
end # module Bmg
|
@@ -5,6 +5,7 @@ module Bmg
|
|
5
5
|
|
6
6
|
def initialize(operand)
|
7
7
|
@operand = operand
|
8
|
+
@materialized = nil
|
8
9
|
end
|
9
10
|
|
10
11
|
def type
|
@@ -40,9 +41,9 @@ module Bmg
|
|
40
41
|
private
|
41
42
|
|
42
43
|
def _materialize
|
43
|
-
return @
|
44
|
+
return @materialized if @materialized
|
44
45
|
|
45
|
-
@
|
46
|
+
@materialized = Relation::InMemory.new(operand.type, operand.to_a)
|
46
47
|
end
|
47
48
|
|
48
49
|
end # class Materialized
|
data/lib/bmg/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bmg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.18.
|
4
|
+
version: 0.18.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bernard Lambeau
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-02-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: predicate
|