diva 0.2.0 → 0.2.1
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 +4 -4
- data/lib/diva/combinator.rb +51 -11
- data/lib/diva/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 294ace1f70016d867a7485564ddcc874b0fa1c34
|
4
|
+
data.tar.gz: ae3ee191438c3fe8a41e0a6963de64f7d243e305
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17d75018efc53746ca4b23ba3c7d64d17efe8e5e733367ee03f6f3dc3c586d9745d8ece953a2779d0723fd15d073278dd03a6764ed6ce152a807cdeef9be3862
|
7
|
+
data.tar.gz: 4465ccf523a84506f4a3c00e127357407a236fe95cabe2e02a263fae9478ca31bb397a40e478d0f0f9e3e7c33f28f03c496f6e8e6721cad7fd511ff294702123
|
data/lib/diva/combinator.rb
CHANGED
@@ -12,9 +12,12 @@ module Diva::Combinable
|
|
12
12
|
# ==== Return
|
13
13
|
# true or false
|
14
14
|
def =~(behavior)
|
15
|
-
|
15
|
+
fail 'Not implement'
|
16
|
+
end
|
17
|
+
|
18
|
+
def ===(behavior)
|
19
|
+
self =~ behavior
|
16
20
|
end
|
17
|
-
alias_method :===, :=~
|
18
21
|
|
19
22
|
# このCombinatorが持っている値のすべての組み合わせのうち、適切に _behavior_
|
20
23
|
# をサポートしている組み合わせについて繰り返すEnumeratorを返す
|
@@ -24,8 +27,8 @@ module Diva::Combinable
|
|
24
27
|
# [レシーバ, 引数] のペアを列挙するEnumerator
|
25
28
|
def enum(behavior)
|
26
29
|
Enumerator.new do |yielder|
|
27
|
-
yielder << [@a, @b] if
|
28
|
-
yielder << [@b, @a] if
|
30
|
+
yielder << [@a, @b] if a_b(behavior)
|
31
|
+
yielder << [@b, @a] if b_a(behavior)
|
29
32
|
end
|
30
33
|
end
|
31
34
|
|
@@ -35,22 +38,46 @@ module Diva::Combinable
|
|
35
38
|
end
|
36
39
|
super
|
37
40
|
end
|
38
|
-
end
|
39
41
|
|
40
|
-
|
41
|
-
|
42
|
-
|
42
|
+
private
|
43
|
+
|
44
|
+
def a_b(behavior)
|
45
|
+
@a.respond_to?(behavior) && @a.__send__(behavior, @b)
|
46
|
+
end
|
47
|
+
|
48
|
+
def b_a(behavior)
|
49
|
+
@b.respond_to?(behavior) && @b.__send__(behavior, @a)
|
43
50
|
end
|
51
|
+
end
|
44
52
|
|
53
|
+
class PluralCombinator < Combinator
|
45
54
|
def enum(behavior)
|
46
55
|
Enumerator.new do |yielder|
|
47
56
|
@b.each do |b|
|
48
|
-
(
|
57
|
+
(b | @a).enum(behavior).each(&yielder.method(:<<))
|
49
58
|
end
|
50
59
|
end
|
51
60
|
end
|
52
61
|
end
|
53
62
|
|
63
|
+
class SingleCombinator < Combinator
|
64
|
+
def =~(behavior)
|
65
|
+
a_b(behavior) || b_a(behavior)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
class AnyCombinator < PluralCombinator
|
70
|
+
def =~(behavior)
|
71
|
+
@b.any?{|b| b | @a =~ behavior }
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
class AllCombinator < PluralCombinator
|
76
|
+
def =~(behavior)
|
77
|
+
@b.all?{|b| b | @a =~ behavior }
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
54
81
|
# _other_ との Diva::Conbinable::Combinator を生成する
|
55
82
|
# ==== Args
|
56
83
|
# [other] Diva::Modelか、Diva::Modelを列挙するEnumerable
|
@@ -58,9 +85,22 @@ module Diva::Combinable
|
|
58
85
|
# Diva::Conbinable::Combinator
|
59
86
|
def |(other)
|
60
87
|
if other.is_a? Enumerable
|
61
|
-
|
88
|
+
AnyCombinator.new(self, other)
|
89
|
+
else
|
90
|
+
SingleCombinator.new(self, other)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
# _other_ との Diva::Conbinable::Combinator を生成する
|
95
|
+
# ==== Args
|
96
|
+
# [other] Diva::Modelか、Diva::Modelを列挙するEnumerable
|
97
|
+
# ==== Return
|
98
|
+
# Diva::Conbinable::Combinator
|
99
|
+
def &(other)
|
100
|
+
if other.is_a? Enumerable
|
101
|
+
AllCombinator.new(self, other)
|
62
102
|
else
|
63
|
-
|
103
|
+
SingleCombinator.new(self, other)
|
64
104
|
end
|
65
105
|
end
|
66
106
|
end
|
data/lib/diva/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: diva
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Toshiaki Asai
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-05-
|
11
|
+
date: 2017-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|