bmg 0.8.0 → 0.9.0

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
  SHA1:
3
- metadata.gz: 4972b019d398ba2be5f7cb73765f120849e0365e
4
- data.tar.gz: 153fbe99bc8947f23919686afe475d955674d8e5
3
+ metadata.gz: eb470e183450764deb107abde24e74ab37889bb1
4
+ data.tar.gz: 5ee77b5b2ad43e0bd433768dd909ddc7038a8e7a
5
5
  SHA512:
6
- metadata.gz: e39d912e26e824d715375c90420a182a6b35de4cadd5d7afb668fe3c761ac19f3bd9384b2843c935b21184fce7ce524a874783298778b43b2360333e2ab47471
7
- data.tar.gz: 6d738735211d6d22e60fce0210bc188d5abf37304e3c7f1311a27b7051fe05919cb691c00c771eeb4fa6b5566ebe9cf5498e2d0c018d39a0dce205cd44a07870
6
+ metadata.gz: 22a0903f17bb116601e3c8a40946b516269f21fd334e38f29b11f30fc8db39c97d1db83fc295f30709c921b6f25c2953dea6acd627affb65f17e0a56af442822
7
+ data.tar.gz: 1773884867ab4c693405711dbbb85f92a2cbcff8d802876b3cd09ec75fc88f28975b4ac905c262f1970e71e651ec974f4edf4bf38dcd5befab20b655d7449f67
@@ -10,9 +10,11 @@ module Bmg
10
10
  :group,
11
11
  :image,
12
12
  :matching,
13
+ :page,
13
14
  :project,
14
15
  :rename,
15
16
  :restrict,
17
+ :rxmatch,
16
18
  :union
17
19
  ]
18
20
 
@@ -88,6 +90,15 @@ module Bmg
88
90
  end
89
91
  protected :_matching
90
92
 
93
+ def page(ordering, page_index, options)
94
+ _page self.type.page(ordering, page_index, options), ordering, page_index, options
95
+ end
96
+
97
+ def _page(type, ordering, page_index, options)
98
+ Operator::Page.new(type, self, ordering, page_index, options)
99
+ end
100
+ protected :_page
101
+
91
102
  def project(attrlist = [])
92
103
  _project self.type.project(attrlist), attrlist
93
104
  end
@@ -129,6 +140,15 @@ module Bmg
129
140
  end
130
141
  protected :_restrict
131
142
 
143
+ def rxmatch(attrs, matcher, options = {})
144
+ _rxmatch type.rxmatch(attrs, matcher, options), attrs, matcher, options
145
+ end
146
+
147
+ def _rxmatch(type, attrs, matcher, options)
148
+ Operator::Rxmatch.new(type, self, attrs, matcher, options)
149
+ end
150
+ protected :_rxmatch
151
+
132
152
  def union(other, options = {})
133
153
  _union self.type.union(other.type), other, options
134
154
  end
@@ -73,7 +73,9 @@ require_relative 'operator/extend'
73
73
  require_relative 'operator/group'
74
74
  require_relative 'operator/image'
75
75
  require_relative 'operator/matching'
76
+ require_relative 'operator/page'
76
77
  require_relative 'operator/project'
77
78
  require_relative 'operator/rename'
78
79
  require_relative 'operator/restrict'
80
+ require_relative 'operator/rxmatch'
79
81
  require_relative 'operator/union'
@@ -0,0 +1,63 @@
1
+ module Bmg
2
+ module Operator
3
+ #
4
+ # Page operator.
5
+ #
6
+ # Takes the n-th page according to some tuple ordering and page size
7
+ #
8
+ class Page
9
+ include Operator::Unary
10
+
11
+ DEFAULT_OPTIONS = {
12
+
13
+ page_size: 100
14
+
15
+ }
16
+
17
+ def initialize(type, operand, ordering, page_index, options)
18
+ raise ArgumentError, "Page index must be > 0" if page_index <= 0
19
+ @type = type
20
+ @operand = operand
21
+ @ordering = ordering
22
+ @page_index = page_index
23
+ @options = DEFAULT_OPTIONS.merge(options)
24
+ end
25
+
26
+ protected
27
+
28
+ attr_reader :ordering, :page_index, :options
29
+
30
+ public
31
+
32
+ def each(&bl)
33
+ page_size = options[:page_size]
34
+ @operand.to_a
35
+ .sort(&comparator)
36
+ .drop(page_size * (page_index-1))
37
+ .take(page_size)
38
+ .each(&bl)
39
+ end
40
+
41
+ def to_ast
42
+ [ :page, operand.to_ast, ordering.dup, page_index, options.dup ]
43
+ end
44
+
45
+ protected ### inspect
46
+
47
+ def comparator
48
+ ->(t1, t2) {
49
+ ordering.each do |attr|
50
+ c = t1[attr] <=> t2[attr]
51
+ return c unless c==0
52
+ end
53
+ 0
54
+ }
55
+ end
56
+
57
+ def args
58
+ [ ordering, page_index, options ]
59
+ end
60
+
61
+ end # class Page
62
+ end # module Operator
63
+ end # module Bmg
@@ -0,0 +1,55 @@
1
+ module Bmg
2
+ module Operator
3
+ #
4
+ # Rxmatch operator.
5
+ #
6
+ # Filters operand's tuples to those whose attributes match a
7
+ # given string or regular expression.
8
+ #
9
+ class Rxmatch
10
+ include Operator::Unary
11
+
12
+ DEFAULT_OPTIONS = {}
13
+
14
+ def initialize(type, operand, attrs, matcher, options)
15
+ @type = type
16
+ @operand = operand
17
+ @attrs = attrs
18
+ @matcher = matcher
19
+ @options = DEFAULT_OPTIONS.merge(options)
20
+ end
21
+
22
+ protected
23
+
24
+ attr_reader :attrs, :matcher, :options
25
+
26
+ public
27
+
28
+ def each
29
+ @operand.each do |tuple|
30
+ against = attrs.map{|a| tuple[a] }.join(" ")
31
+ yield(tuple) if against.match(matcher)
32
+ end
33
+ end
34
+
35
+ def to_ast
36
+ [ :rxmatch, operand.to_ast, attrs.dup, matcher, options.dup ]
37
+ end
38
+
39
+ protected
40
+
41
+ def _restrict(type, predicate)
42
+ @operand
43
+ .restrict(predicate)
44
+ .rxmatch(attrs, matcher, options)
45
+ end
46
+
47
+ protected ### inspect
48
+
49
+ def args
50
+ [ attrs, matcher, options ]
51
+ end
52
+
53
+ end # class Rxmatch
54
+ end # module Operator
55
+ end # module Bmg
@@ -42,7 +42,11 @@ module Bmg
42
42
  end
43
43
 
44
44
  def matching(right, on)
45
- ANY
45
+ self
46
+ end
47
+
48
+ def page(ordering, page_size, options)
49
+ self
46
50
  end
47
51
 
48
52
  def project(attrlist)
@@ -57,6 +61,10 @@ module Bmg
57
61
  Type.new(@predicate & predicate)
58
62
  end
59
63
 
64
+ def rxmatch(attrs, matcher, options)
65
+ self
66
+ end
67
+
60
68
  def union(other)
61
69
  Type.new(@predicate | other.predicate)
62
70
  end
@@ -1,7 +1,7 @@
1
1
  module Bmg
2
2
  module Version
3
3
  MAJOR = 0
4
- MINOR = 8
4
+ MINOR = 9
5
5
  TINY = 0
6
6
  end
7
7
  VERSION = "#{Version::MAJOR}.#{Version::MINOR}.#{Version::TINY}"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bmg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bernard Lambeau
@@ -117,9 +117,11 @@ files:
117
117
  - lib/bmg/operator/group.rb
118
118
  - lib/bmg/operator/image.rb
119
119
  - lib/bmg/operator/matching.rb
120
+ - lib/bmg/operator/page.rb
120
121
  - lib/bmg/operator/project.rb
121
122
  - lib/bmg/operator/rename.rb
122
123
  - lib/bmg/operator/restrict.rb
124
+ - lib/bmg/operator/rxmatch.rb
123
125
  - lib/bmg/operator/union.rb
124
126
  - lib/bmg/reader.rb
125
127
  - lib/bmg/reader/csv.rb