bmg 0.18.8 → 0.18.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9489f2f59b1f3fc644c4a29ee53ba08662f9671ebda9cc6b0340a98c6daf20d9
4
- data.tar.gz: f0506ba0dbea31d5d3a1c3f4e3edbdf0ea9ef88e40b386445494f6cd61f759c1
3
+ metadata.gz: e287adcc94d2a0a5a88604e90cb34895ff801b137478c3cfa8b32d2093e7289c
4
+ data.tar.gz: 148775b4bdfbcb45099ed2587268243eef46b8a214d9bbf5f9f3abc9960764f2
5
5
  SHA512:
6
- metadata.gz: a3de98440bf031b653d2ef9f7cc6f89ab44969304ca6fdd04cadc514e617a17d5b8b5bfeb791bc03de576acac5431a1d85a52a413f59932aae77ee3f41175ff3
7
- data.tar.gz: b583e4ade1f71740afaf2a43c5a0dad8eb27557de533b4cbd61c7f632e79d612a85340897e01ed571a91572acd4f2ab65c00d2b9e00d4d8a8cc8b97919c46102
6
+ metadata.gz: ae86583f677f487bb3b6e71fa1a5ed07cc731bd927cf74716d68818d330809f86aaddb98c8a8c9848f68c3b0a8ba183996029ecf745db377d740b1c4da59b995
7
+ data.tar.gz: a0fca7d1f3fa2ecc8097a0167d5ec9767a047b61af54212b16030dfe23a46c05e3597641c0c125c40f0652fbdc15d593e7201cc9b430467e90216af0630e4c5d
@@ -22,6 +22,7 @@ module Bmg
22
22
 
23
23
  DEFAULT_OPTIONS = {
24
24
  :postprocessor => :none,
25
+ :postprocessor_condition => :all,
25
26
  :split => "_"
26
27
  }
27
28
 
@@ -167,7 +168,7 @@ module Bmg
167
168
 
168
169
  def normalize_options(options)
169
170
  opts = DEFAULT_OPTIONS.merge(options)
170
- opts[:postprocessor] = NoLeftJoinNoise.new(opts[:postprocessor])
171
+ opts[:postprocessor] = NoLeftJoinNoise.new(opts[:postprocessor], opts[:postprocessor_condition])
171
172
  opts
172
173
  end
173
174
 
@@ -209,17 +210,17 @@ module Bmg
209
210
  class NoLeftJoinNoise
210
211
 
211
212
  REMOVERS = {
212
- nil: ->(t,k){ t[k] = nil },
213
- delete: ->(t,k){ t.delete(k) },
214
- none: ->(t,k){ t }
213
+ nil: ->(t,k){ t[k] = nil },
214
+ delete: ->(t,k){ t.delete(k) },
215
+ none: ->(t,k){ t }
215
216
  }
216
217
 
217
- def self.new(remover)
218
+ def self.new(remover, remover_condition = :all)
218
219
  return remover if remover.is_a?(NoLeftJoinNoise)
219
220
  super
220
221
  end
221
222
 
222
- def initialize(remover)
223
+ def initialize(remover, remover_condition = :all)
223
224
  @remover_to_s = remover
224
225
  @remover = case remover
225
226
  when NilClass then REMOVERS[:none]
@@ -229,22 +230,35 @@ module Bmg
229
230
  else
230
231
  raise "Invalid remover `#{remover}`"
231
232
  end
233
+ @remover_condition = case remover_condition
234
+ when :all then ->(tuple){ all_nil?(tuple) }
235
+ when :id then ->(tuple){ id_nil?(tuple) }
236
+ else
237
+ raise "Invalid remover condition `#{remover_condition}`"
238
+ end
232
239
  end
233
240
  attr_reader :remover
234
241
 
235
242
  def call(tuple)
236
243
  tuple.each_key do |k|
237
244
  call(tuple[k]) if tuple[k].is_a?(Hash)
238
- @remover.call(tuple, k) if tuple[k].is_a?(Hash) && all_nil?(tuple[k])
245
+ @remover.call(tuple, k) if tuple[k].is_a?(Hash) && @remover_condition.call(tuple[k])
239
246
  end
240
247
  tuple
241
248
  end
242
249
 
243
250
  def all_nil?(tuple)
244
251
  return false unless tuple.is_a?(Hash)
252
+
245
253
  tuple.all?{|(k,v)| v.nil? || all_nil?(tuple[k]) }
246
254
  end
247
255
 
256
+ def id_nil?(tuple)
257
+ return false unless tuple.is_a?(Hash)
258
+
259
+ tuple[:id].nil?
260
+ end
261
+
248
262
  def inspect
249
263
  @remover_to_s.inspect
250
264
  end
@@ -4,6 +4,7 @@ module Bmg
4
4
  include Reader
5
5
 
6
6
  DEFAULT_OPTIONS = {
7
+ sheet: 0,
7
8
  skip: 0,
8
9
  row_num: true
9
10
  }
@@ -19,7 +20,7 @@ module Bmg
19
20
  require 'roo'
20
21
  xlsx = Roo::Spreadsheet.open(@path, @options)
21
22
  headers = nil
22
- xlsx.sheet(0)
23
+ xlsx.sheet(@options[:sheet])
23
24
  .each
24
25
  .drop(@options[:skip])
25
26
  .each_with_index
@@ -0,0 +1,25 @@
1
+ module Bmg
2
+ class Summarizer
3
+ #
4
+ # First summarizer.
5
+ #
6
+ # Example:
7
+ #
8
+ # # direct ruby usage
9
+ # Bmg::Summarizer.first(:qty, :order => [:id]).summarize(...)
10
+ #
11
+ class First < Positional
12
+
13
+ def choose(t1, t2)
14
+ t1
15
+ end
16
+
17
+ end # class First
18
+
19
+ # Factors a first summarizer
20
+ def self.first(*args, &bl)
21
+ First.new(*args, &bl)
22
+ end
23
+
24
+ end # class Summarizer
25
+ end # module Bmg
@@ -0,0 +1,25 @@
1
+ module Bmg
2
+ class Summarizer
3
+ #
4
+ # Last summarizer.
5
+ #
6
+ # Example:
7
+ #
8
+ # # direct ruby usage
9
+ # Bmg::Summarizer.last(:qty, :order => [:id]).summarize(...)
10
+ #
11
+ class Last < Positional
12
+
13
+ def choose(t1, t2)
14
+ t2
15
+ end
16
+
17
+ end # class Last
18
+
19
+ # Factors a last summarizer
20
+ def self.last(*args, &bl)
21
+ Last.new(*args, &bl)
22
+ end
23
+
24
+ end # class Summarizer
25
+ end # module Bmg
@@ -0,0 +1,33 @@
1
+ module Bmg
2
+ class Summarizer
3
+ # See First and Last
4
+ class Positional < Summarizer
5
+
6
+ def initialize(*args, &block)
7
+ super
8
+ raise ArgumentError, "Missing order" unless options[:order]
9
+ @ordering = Ordering.new(options[:order])
10
+ end
11
+ attr_reader :ordering
12
+
13
+ def least
14
+ nil
15
+ end
16
+
17
+ def happens(memo, tuple)
18
+ if memo.nil?
19
+ tuple
20
+ else
21
+ c = ordering.call(memo, tuple)
22
+ c <= 0 ? choose(memo, tuple) : choose(tuple, memo)
23
+ end
24
+ end
25
+
26
+ def finalize(memo)
27
+ return nil if memo.nil?
28
+ extract_value(memo)
29
+ end
30
+
31
+ end # class Positional
32
+ end # class Summarizer
33
+ end # module Bmg
@@ -169,3 +169,6 @@ require_relative 'summarizer/concat'
169
169
  require_relative 'summarizer/by_proc'
170
170
  require_relative 'summarizer/multiple'
171
171
  require_relative 'summarizer/value_by'
172
+ require_relative 'summarizer/positional'
173
+ require_relative 'summarizer/first'
174
+ require_relative 'summarizer/last'
@@ -6,8 +6,12 @@ module Bmg
6
6
  end
7
7
  attr_reader :attrs
8
8
 
9
+ def call(t1, t2)
10
+ comparator.call(t1, t2)
11
+ end
12
+
9
13
  def comparator
10
- ->(t1, t2) {
14
+ @comparator ||= ->(t1, t2) {
11
15
  attrs.each do |(attr,direction)|
12
16
  c = t1[attr] <=> t2[attr]
13
17
  return (direction == :desc ? -c : c) unless c==0
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 = 8
5
+ TINY = 9
6
6
  end
7
7
  VERSION = "#{Version::MAJOR}.#{Version::MINOR}.#{Version::TINY}"
8
8
  end
metadata CHANGED
@@ -1,35 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bmg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.18.8
4
+ version: 0.18.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bernard Lambeau
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-15 00:00:00.000000000 Z
11
+ date: 2021-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: predicate
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: 2.5.0
20
17
  - - "~>"
21
18
  - !ruby/object:Gem::Version
22
19
  version: '2.5'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 2.5.0
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- version: 2.5.0
30
27
  - - "~>"
31
28
  - !ruby/object:Gem::Version
32
29
  version: '2.5'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 2.5.0
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: path
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -274,10 +274,13 @@ files:
274
274
  - lib/bmg/summarizer/count.rb
275
275
  - lib/bmg/summarizer/distinct.rb
276
276
  - lib/bmg/summarizer/distinct_count.rb
277
+ - lib/bmg/summarizer/first.rb
278
+ - lib/bmg/summarizer/last.rb
277
279
  - lib/bmg/summarizer/max.rb
278
280
  - lib/bmg/summarizer/min.rb
279
281
  - lib/bmg/summarizer/multiple.rb
280
282
  - lib/bmg/summarizer/percentile.rb
283
+ - lib/bmg/summarizer/positional.rb
281
284
  - lib/bmg/summarizer/stddev.rb
282
285
  - lib/bmg/summarizer/sum.rb
283
286
  - lib/bmg/summarizer/value_by.rb
@@ -314,7 +317,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
314
317
  - !ruby/object:Gem::Version
315
318
  version: '0'
316
319
  requirements: []
317
- rubygems_version: 3.0.8
320
+ rubygems_version: 3.1.4
318
321
  signing_key:
319
322
  specification_version: 4
320
323
  summary: Bmg is Alf's successor.