bmg 0.20.5 → 0.21.0
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 +5 -5
- data/lib/bmg/reader/csv.rb +1 -3
- data/lib/bmg/support/ordering.rb +1 -11
- data/lib/bmg/support/output_preferences.rb +1 -27
- data/lib/bmg/version.rb +2 -2
- data/lib/bmg/writer/csv.rb +1 -3
- data/lib/bmg/writer/xlsx.rb +7 -9
- data/lib/bmg/writer.rb +0 -11
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ef6b320621feeff681bb76b804da274ae055573c
|
4
|
+
data.tar.gz: 2a119b1aa5838fbb2b657332de25fd22cc10dbb6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e33cda560cb1c3f119940745c63f45884a406d7b0bce113d08a43d2f374a9a658ab47667c63919d16d5863f6867f2d29808d23a049efe9e34487a282e29c9c82
|
7
|
+
data.tar.gz: ec437125ffbf4e41633b33c6ddc5eedeccef915dd2201f7d0f2a54e8ba348f272e67195ebc57cd8a8e839b07a0fa1aacb957eacf6723d34a42b03dac1d4783ec
|
data/lib/bmg/reader/csv.rb
CHANGED
data/lib/bmg/support/ordering.rb
CHANGED
@@ -2,13 +2,7 @@ module Bmg
|
|
2
2
|
class Ordering
|
3
3
|
|
4
4
|
def initialize(attrs)
|
5
|
-
@attrs =
|
6
|
-
[]
|
7
|
-
elsif attrs.first.is_a?(Symbol)
|
8
|
-
attrs.map{|a| [a, :asc] }
|
9
|
-
else
|
10
|
-
attrs
|
11
|
-
end
|
5
|
+
@attrs = attrs
|
12
6
|
end
|
13
7
|
attr_reader :attrs
|
14
8
|
|
@@ -39,9 +33,5 @@ module Bmg
|
|
39
33
|
0
|
40
34
|
end
|
41
35
|
|
42
|
-
def to_a
|
43
|
-
attrs.to_a
|
44
|
-
end
|
45
|
-
|
46
36
|
end # class Ordering
|
47
37
|
end # module Bmg
|
@@ -3,7 +3,6 @@ module Bmg
|
|
3
3
|
|
4
4
|
DEFAULT_PREFS = {
|
5
5
|
attributes_ordering: nil,
|
6
|
-
tuple_ordering: nil,
|
7
6
|
extra_attributes: :after
|
8
7
|
}
|
9
8
|
|
@@ -18,12 +17,6 @@ module Bmg
|
|
18
17
|
new(arg)
|
19
18
|
end
|
20
19
|
|
21
|
-
def tuple_ordering
|
22
|
-
return nil unless to = options[:tuple_ordering]
|
23
|
-
|
24
|
-
@tuple_ordering = Ordering.new(to)
|
25
|
-
end
|
26
|
-
|
27
20
|
def attributes_ordering
|
28
21
|
options[:attributes_ordering]
|
29
22
|
end
|
@@ -32,29 +25,10 @@ module Bmg
|
|
32
25
|
options[:extra_attributes]
|
33
26
|
end
|
34
27
|
|
35
|
-
def grouping_attributes
|
36
|
-
options[:grouping_attributes]
|
37
|
-
end
|
38
|
-
|
39
|
-
def erase_redundance_in_group(before, current)
|
40
|
-
return [nil, current] unless ga = grouping_attributes
|
41
|
-
return [current, current] unless before
|
42
|
-
|
43
|
-
new_before, new_current = current.dup, current.dup
|
44
|
-
ga.each do |attr|
|
45
|
-
return [new_before, new_current] unless before[attr] == current[attr]
|
46
|
-
new_current[attr] = nil
|
47
|
-
end
|
48
|
-
[new_before, new_current]
|
49
|
-
end
|
50
|
-
|
51
28
|
def order_attrlist(attrlist)
|
52
29
|
return attrlist if attributes_ordering.nil?
|
53
|
-
|
54
30
|
index = Hash[attributes_ordering.each_with_index.to_a]
|
55
|
-
|
56
|
-
base = attrlist & attributes_ordering if extra_attributes == :ignored
|
57
|
-
base.sort{|a,b|
|
31
|
+
attrlist.sort{|a,b|
|
58
32
|
ai, bi = index[a], index[b]
|
59
33
|
if ai && bi
|
60
34
|
ai <=> bi
|
data/lib/bmg/version.rb
CHANGED
data/lib/bmg/writer/csv.rb
CHANGED
@@ -16,14 +16,12 @@ module Bmg
|
|
16
16
|
require 'csv'
|
17
17
|
string_or_io, to_s = string_or_io.nil? ? [StringIO.new, true] : [string_or_io, false]
|
18
18
|
headers, csv = infer_headers(relation.type), nil
|
19
|
-
|
20
|
-
each_tuple(relation) do |tuple,i|
|
19
|
+
relation.each do |tuple|
|
21
20
|
if csv.nil?
|
22
21
|
headers = infer_headers(tuple) if headers.nil?
|
23
22
|
csv_opts = csv_options.merge(headers: headers)
|
24
23
|
csv = CSV.new(string_or_io, **csv_opts)
|
25
24
|
end
|
26
|
-
previous, tuple = output_preferences.erase_redundance_in_group(previous, tuple)
|
27
25
|
csv << headers.map{|h| tuple[h] }
|
28
26
|
end
|
29
27
|
to_s ? string_or_io.string : string_or_io
|
data/lib/bmg/writer/xlsx.rb
CHANGED
@@ -6,11 +6,11 @@ module Bmg
|
|
6
6
|
DEFAULT_OPTIONS = {
|
7
7
|
}
|
8
8
|
|
9
|
-
def initialize(
|
10
|
-
@
|
9
|
+
def initialize(csv_options, output_preferences = nil)
|
10
|
+
@csv_options = DEFAULT_OPTIONS.merge(csv_options)
|
11
11
|
@output_preferences = OutputPreferences.dress(output_preferences)
|
12
12
|
end
|
13
|
-
attr_reader :
|
13
|
+
attr_reader :csv_options, :output_preferences
|
14
14
|
|
15
15
|
def call(relation, path)
|
16
16
|
require 'write_xlsx'
|
@@ -21,24 +21,22 @@ module Bmg
|
|
21
21
|
attr_reader :workbook, :worksheet
|
22
22
|
|
23
23
|
def _call(relation, path)
|
24
|
-
@workbook =
|
25
|
-
@worksheet =
|
24
|
+
@workbook = WriteXLSX.new(path)
|
25
|
+
@worksheet = workbook.add_worksheet
|
26
26
|
|
27
27
|
headers = infer_headers(relation.type)
|
28
|
-
|
29
|
-
each_tuple(relation) do |tuple,i|
|
28
|
+
relation.each_with_index do |tuple,i|
|
30
29
|
headers = infer_headers(tuple) if headers.nil?
|
31
30
|
headers.each_with_index do |h,i|
|
32
31
|
worksheet.write_string(0, i, h)
|
33
32
|
end if i == 0
|
34
|
-
before, tuple = output_preferences.erase_redundance_in_group(before, tuple)
|
35
33
|
headers.each_with_index do |h,j|
|
36
34
|
meth, *args = write_pair(tuple[h])
|
37
35
|
worksheet.send(meth, 1+i, j, *args)
|
38
36
|
end
|
39
37
|
end
|
40
38
|
|
41
|
-
workbook.close
|
39
|
+
workbook.close
|
42
40
|
path
|
43
41
|
end
|
44
42
|
|
data/lib/bmg/writer.rb
CHANGED
@@ -12,17 +12,6 @@ module Bmg
|
|
12
12
|
attrlist ? output_preferences.order_attrlist(attrlist) : nil
|
13
13
|
end
|
14
14
|
|
15
|
-
def each_tuple(relation, &bl)
|
16
|
-
if ordering = output_preferences.tuple_ordering
|
17
|
-
relation
|
18
|
-
.to_a
|
19
|
-
.sort{|t1,t2| ordering.compare_attrs(t1, t2) }
|
20
|
-
.each_with_index(&bl)
|
21
|
-
else
|
22
|
-
relation.each_with_index(&bl)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
15
|
end # module Writer
|
27
16
|
end # module Bmg
|
28
17
|
require_relative 'writer/csv'
|
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.
|
4
|
+
version: 0.21.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bernard Lambeau
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-05-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: predicate
|
@@ -320,7 +320,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
320
320
|
- !ruby/object:Gem::Version
|
321
321
|
version: '0'
|
322
322
|
requirements: []
|
323
|
-
|
323
|
+
rubyforge_project:
|
324
|
+
rubygems_version: 2.6.14.4
|
324
325
|
signing_key:
|
325
326
|
specification_version: 4
|
326
327
|
summary: Bmg is Alf's successor.
|