eqq 0.0.3 → 0.0.4

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: 22307661e329771fea7efcd7c282d17eda0130d0edb7aec3088257b21b73e4ba
4
- data.tar.gz: ebc3138ade59e38f9bc34a42a93654d3a6ab1564a48b47df13d65ed7227c7488
3
+ metadata.gz: 53f4f6ec548d800742874bd0d98b015891227be295c9b22a0a3cb89eafce301b
4
+ data.tar.gz: 58d3f0a0513a7a4eff20d5aea9d60682d415e1582bc7fd9f39166894d03c75da
5
5
  SHA512:
6
- metadata.gz: 16ae2b50b3c81291028946ec6ddb8753c06bc7fc472f29ab00b3f69b9136540f26079b8c23f983d0bf1482f93543744f2fae557bb0ef71f6fdcc73f115df9455
7
- data.tar.gz: eced8529614ce3b1b8a4cc4087d58943bdbaabd0637a86bb10bcafe472ccdece82bae71d390fde84e95176318961e4ef74207ab4debc6e117411608f2e074176
6
+ metadata.gz: 0eb69ecb3e22473df10aa8256191d03d02cfbd0cc7243d096c574d56f3d00e1932bda1b5d58fe3504b5da7cd68cdd0fb5c59ca91bba94bdef60a9e65d21eaf6e
7
+ data.tar.gz: 8d0393dc91eef5a40e144ab72e374e422f75302ca3b187bb8b24014ff074eca187c84ddd060e9344e3d5b75d56ed34b75e8869ed5d3cb5812f7a59a3080500b1
data/README.md CHANGED
@@ -12,7 +12,7 @@ Require Ruby 2.6 or later
12
12
  Add below code into your Gemfile
13
13
 
14
14
  ```ruby
15
- gem 'eqq', '0.0.3'
15
+ gem 'eqq', '0.0.4'
16
16
  ```
17
17
 
18
18
  ### Overview
@@ -63,6 +63,15 @@ ret_in_case = (
63
63
  )
64
64
 
65
65
  p ret_in_case #=> Should be matched here! :)
66
+
67
+ class MyClass
68
+ include Eqq::Buildable
69
+
70
+ def example
71
+ [4.2, 42, 42.0, 420].grep(OR(AND(Float, 20..50), Integer))
72
+ end
73
+ end
74
+ MyClass.new.example #=> [42, 42.0, 420]
66
75
  ```
67
76
 
68
77
  ### Explanation
@@ -86,34 +95,36 @@ They can take this interface as the `pattern`.
86
95
  And you already saw. All of patterns can be mixed with other patterns as a parts.
87
96
  Reuse as you wish!
88
97
 
89
- Major builders as below
98
+ ### Builders
90
99
 
91
- * OR(*patterns) - Product returns true when matched even one pattern
92
- * AND(*patterns) - Product returns true when matched all patterns
93
- * NOT(pattern) - Product returns true when not matched the pattern
94
- * CAN(*method_names) - Product returns true when it has all of the methods (checked with `respond_to?`)
95
- * RESCUE(exception_class/module, pattern) - Product returns true when the pattern raises the exception
96
- * QUIET(*patterns) - Product returns true when all patterns did not raise any exception
97
- * EQ(object) - Product returns true when matched with `#==`
98
- * SAME(object) - Product returns true when matched with `#equal?`
99
- * SEND(name, pattern) - Basically provided for Enumerable
100
- * BOOLEAN() - Product returns true when matched to true or false
101
- * ANYTHING() - Product returns true, always true
100
+ * OR(*patterns) / {Eqq::Buildable#OR} - Product returns `true` when matched even one pattern
101
+ * AND(*patterns) / {Eqq::Buildable#AND} - Product returns `true` when matched all patterns
102
+ * NOT(pattern) / {Eqq::Buildable#NOT} - Product returns `true` when not matched the pattern
103
+ * CAN(*method_names) / {Eqq::Buildable#CAN} - Product returns `true` when it has all of the methods (checked with `respond_to?`)
104
+ * RESCUE(exception_class/module, pattern) / {Eqq::Buildable#RESCUE} - Product returns `true` when the pattern raises the exception
105
+ * QUIET(*patterns) / {Eqq::Buildable#QUIET} - Product returns `true` when all patterns did not raise any exception
106
+ * EQ(object) / {Eqq::Buildable#EQ} - Product returns `true` when matched with `#==`
107
+ * SAME(object) / {Eqq::Buildable#SAME} - Product returns `true` when matched with `#equal?`
108
+ * SEND(name, pattern) / {Eqq::Buildable#SEND} - Basically provided for Enumerable
109
+ * BOOLEAN() / {Eqq::Buildable#BOOLEAN} - Product returns `true` when matched to `true` or `false`
110
+ * ANYTHING() / {Eqq::Buildable#ANYTHING} - Product returns `true`, always `true`
111
+ * XOR(pattern1, pattern2) / {Eqq::Buildable#XOR} - Product returns `true` when matched one of the pattern, when matched both returns `false`
112
+ * NAND(*patterns) / {Eqq::Buildable#NAND} - Product is inverted {Eqq::Buildable#AND}
113
+ * NOR(*patterns) / {Eqq::Buildable#NOR} - Product is inverted {Eqq::Buildable#OR}
102
114
 
103
- Minor builders as below, please see [API documents](https://kachick.github.io/eqq) for them.
115
+ ### Additional information
104
116
 
105
- * NAND
106
- * NOR
107
- * XOR
117
+ When you feel annoy to write `Eqq` in many place, 2 ways exist.
108
118
 
109
- When you feel annoy to write `Eqq` in many place, please use `Eqq.define`.
110
- In the block scope, all builder methods can be used without receiver specifying.
119
+ * `Eqq.define` - In the block scope, all builder methods can be used without receiver
120
+ * `include Eqq::Buildable` - In the class/module, all builders can be used as own method
111
121
 
112
- This gem provide [ruby/rbs](https://github.com/ruby/rbs) signature
122
+ This gem provides [ruby/rbs](https://github.com/ruby/rbs) signatures
113
123
 
114
124
  ## Links
115
125
 
116
126
  * [Repository](https://github.com/kachick/eqq)
127
+ * [API documents](https://kachick.github.io/eqq)
117
128
 
118
129
  ## NOTE
119
130
 
data/lib/eqq.rb CHANGED
@@ -6,8 +6,12 @@
6
6
 
7
7
  require_relative 'eqq/version'
8
8
 
9
+ # Pattern objects builder
9
10
  module Eqq
11
+ # Base error of this library
10
12
  class Error < StandardError; end
13
+
14
+ # Raised when found some products are invalid as a pattern object
11
15
  class InvalidProductError < Error; end
12
16
 
13
17
  class << self
@@ -25,6 +29,7 @@ module Eqq
25
29
  end
26
30
 
27
31
  # @return [#===]
32
+ # @raise [InvalidProductError] if the return value is invalid as a pattern object
28
33
  def define(&block)
29
34
  pattern = DSLScope.new.instance_exec(&block)
30
35
  raise InvalidProductError unless valid?(pattern)
@@ -42,4 +47,5 @@ module Eqq
42
47
  class DSLScope
43
48
  include Buildable
44
49
  end
50
+ private_constant :DSLScope
45
51
  end
data/lib/eqq/buildable.rb CHANGED
@@ -2,10 +2,11 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Eqq
5
+ # Actually having definitions for the pattern builders
5
6
  module Buildable
6
- extend self
7
-
8
7
  class << self
8
+ # When the inspection is failed some unexpected reasons, it will fallback to this value
9
+ # This value is not fixed as a spec, might be changed in future
9
10
  INSPECTION_FALLBACK = 'UninspectableObject'
10
11
 
11
12
  # @api private
@@ -43,6 +44,8 @@ module Eqq
43
44
  end
44
45
  end
45
46
 
47
+ # Product returns `true` when matched all patterns
48
+ #
46
49
  # @param pattern1 [Proc, Method, #===]
47
50
  # @param pattern2 [Proc, Method, #===]
48
51
  # @param patterns [Array<Proc, Method, #===>]
@@ -60,6 +63,8 @@ module Eqq
60
63
  product
61
64
  end
62
65
 
66
+ # Product is inverted {#AND}
67
+ #
63
68
  # @param pattern1 [Proc, Method, #===]
64
69
  # @param pattern2 [Proc, Method, #===]
65
70
  # @param patterns [Array<Proc, Method, #===>]
@@ -68,6 +73,8 @@ module Eqq
68
73
  NOT(AND(pattern1, pattern2, *patterns))
69
74
  end
70
75
 
76
+ # Product returns `true` when matched even one pattern
77
+ #
71
78
  # @param pattern1 [Proc, Method, #===]
72
79
  # @param pattern2 [Proc, Method, #===]
73
80
  # @param patterns [Array<Proc, Method, #===>]
@@ -84,6 +91,8 @@ module Eqq
84
91
  product
85
92
  end
86
93
 
94
+ # Product is inverted {#OR}
95
+ #
87
96
  # @param pattern1 [Proc, Method, #===]
88
97
  # @param pattern2 [Proc, Method, #===]
89
98
  # @param patterns [Array<Proc, Method, #===>]
@@ -92,6 +101,8 @@ module Eqq
92
101
  NOT(OR(pattern1, pattern2, *patterns))
93
102
  end
94
103
 
104
+ # Product returns `true` when matched one of the pattern, when matched both returns `false`
105
+ #
95
106
  # @param pattern1 [Proc, Method, #===]
96
107
  # @param pattern2 [Proc, Method, #===]
97
108
  # @return [Proc]
@@ -107,6 +118,8 @@ module Eqq
107
118
  product
108
119
  end
109
120
 
121
+ # Product returns `true` when not matched the pattern
122
+ #
110
123
  # @param pattern [Proc, Method, #===]
111
124
  # @return [Proc]
112
125
  def NOT(pattern)
@@ -119,6 +132,8 @@ module Eqq
119
132
  product
120
133
  end
121
134
 
135
+ # Product returns `true` when matched with `#==`
136
+ #
122
137
  # @param obj [#==]
123
138
  # @return [Proc]
124
139
  def EQ(obj)
@@ -127,6 +142,8 @@ module Eqq
127
142
  end
128
143
  end
129
144
 
145
+ # Product returns `true` when matched with `#equal?`
146
+ #
130
147
  # @param obj [#equal?]
131
148
  # @return [Proc]
132
149
  def SAME(obj)
@@ -135,6 +152,8 @@ module Eqq
135
152
  end
136
153
  end
137
154
 
155
+ # Product returns `true` when it has all of the methods (checked with `respond_to?`)
156
+ #
138
157
  # @param message1 [Symbol, String, #to_sym]
139
158
  # @param messages [Array<Symbol, String, #to_sym>]
140
159
  # @return [Proc]
@@ -162,6 +181,8 @@ module Eqq
162
181
  product
163
182
  end
164
183
 
184
+ # Product returns `true` when all patterns did not raise any exception
185
+ #
165
186
  # @param pattern1 [Proc, Method, #===]
166
187
  # @param patterns [Array<Proc, Method, #===>]
167
188
  # @return [Proc]
@@ -186,6 +207,8 @@ module Eqq
186
207
  product
187
208
  end
188
209
 
210
+ # Product returns `true` when the pattern raises the exception
211
+ #
189
212
  # @param mod [Module]
190
213
  # @param pattern [Proc, Method, #===]
191
214
  # @return [Proc]
@@ -209,6 +232,8 @@ module Eqq
209
232
  product
210
233
  end
211
234
 
235
+ # Basically provided for Enumerable
236
+ #
212
237
  # @param name [Symbol, String, #to_sym]
213
238
  # @param pattern [Proc, Method, #===]
214
239
  # @return [Proc]
@@ -235,15 +260,20 @@ module Eqq
235
260
  Buildable.set_inspect(name: 'ANYTHING', product: ANYTHING, arguments: [])
236
261
  private_constant :ANYTHING
237
262
 
238
- # @return [ANYTHING]
263
+ # Product returns `true`, always `true`
264
+ #
265
+ # @return [Proc]
239
266
  def ANYTHING
240
267
  ANYTHING
241
268
  end
242
269
 
243
- BOOLEAN = OR(SAME(true), SAME(false))
270
+ BOOLEAN = ->v { true.equal?(v) || false.equal?(v) }
271
+ Buildable.set_inspect(name: 'BOOLEAN', product: BOOLEAN, arguments: [])
244
272
  private_constant :BOOLEAN
245
273
 
246
- # @return [BOOLEAN]
274
+ # Product returns `true` when matched to `true` or `false`
275
+ #
276
+ # @return [Proc]
247
277
  def BOOLEAN
248
278
  BOOLEAN
249
279
  end
data/lib/eqq/version.rb CHANGED
@@ -2,5 +2,6 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Eqq
5
- VERSION = '0.0.3'
5
+ # This will be same as latest published gem version
6
+ VERSION = '0.0.4'
6
7
  end
data/sig/eqq.rbs CHANGED
@@ -30,7 +30,6 @@ module Eqq
30
30
  # A private API. Should not be used in your code.
31
31
  def self.validate_patterns: (*untyped) -> void
32
32
 
33
- extend Buildable
34
33
  def OR: (_Patternable, _Patternable, *_Patternable) -> product
35
34
  def AND: (_Patternable, _Patternable, *_Patternable) -> product
36
35
  def NAND: (_Patternable, _Patternable, *_Patternable) -> product
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eqq
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kenichi Kamiya
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-02 00:00:00.000000000 Z
11
+ date: 2021-06-03 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: " [4.2, 42, 42.0, 420].grep(Eqq.AND(Integer, 20..50)) #=> [42]\n"
14
14
  email: