bmg 0.18.13 → 0.18.14

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
  SHA1:
3
- metadata.gz: 0ceadf8947aa041841941225e88396cc37ff7319
4
- data.tar.gz: 9c695d3305101ff4a73bcdef5e3788648e9b2d27
3
+ metadata.gz: 8541ab1e17726eb751772cc29a3d198f8bc021d7
4
+ data.tar.gz: a4e07beb7b994d3ac6dda214e3a75822a1a3eb07
5
5
  SHA512:
6
- metadata.gz: 70db4550decd609934e1d8d643983766b5b50b9f0354b2405dfdc710b9580a885e4754c907ed5011856e905308af9647c029f0dd612657e72b45af0465eaced2
7
- data.tar.gz: 5ed5e7f6d1d9baa8070112a36229e8961e4b5a531acbdac808fcf1f5c008fc91ae3ceadc5c3b4c1d0ace22ca6f861074e79b6d957498740a8fba3d5e99875068
6
+ metadata.gz: '063179c6a79505b6baaaf800f56a35dc7084b95ac4fa2c73acc92e809bb1d164d99bb3ce6120863d3b87886f8e21b3bc3579a1043e01dc2938ff6c278a4c08c3'
7
+ data.tar.gz: 3fe57b85503565d547522f4a41ad608ca3839add2305e5108b212f269a4d76adb4d681da58cca01bea564c1ce24b70922215923f3df332d5a7d51dadc09a2ee8
@@ -10,32 +10,27 @@ module Bmg
10
10
  }
11
11
 
12
12
  def initialize(type, path, options = {})
13
- @type = type
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
- require 'roo'
21
- xlsx = Roo::Spreadsheet.open(@path, @options)
22
- headers = nil
23
- xlsx.sheet(@options[:sheet])
24
- .each
25
- .drop(@options[:skip])
26
- .each_with_index
27
- .each do |row, i|
28
- if i==0
29
- headers = row.map{|c| c.to_s.strip.to_sym }
30
- else
31
- init = init_tuple(i)
32
- tuple = (0...headers.size)
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 init_tuple(i)
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
- { :row_num => i }
56
- when FalseClass
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 @operand if @operand.is_a?(Relation::InMemory)
44
+ return @materialized if @materialized
44
45
 
45
- @operand = Relation::InMemory.new(operand.type, operand.to_a)
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
@@ -2,7 +2,7 @@ module Bmg
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 18
5
- TINY = 13
5
+ TINY = 14
6
6
  end
7
7
  VERSION = "#{Version::MAJOR}.#{Version::MINOR}.#{Version::TINY}"
8
8
  end
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.13
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-01-25 00:00:00.000000000 Z
11
+ date: 2022-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: predicate