diva 0.2.0 → 0.2.1

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: bc21e64173564102b7a3da104909d3a1742e5c58
4
- data.tar.gz: 0c826bb45017d63bde247bc292e775e04b17b9fc
3
+ metadata.gz: 294ace1f70016d867a7485564ddcc874b0fa1c34
4
+ data.tar.gz: ae3ee191438c3fe8a41e0a6963de64f7d243e305
5
5
  SHA512:
6
- metadata.gz: 17bdfd00b4008192e9b859276a9684b5a3b475d6dde53f2e94b8845236373f95f66fdda5db0410fe29cb19acfb4bbffc3239809f423005ee4c104072a8d0bebd
7
- data.tar.gz: 534176c4015edc96efc3714c004692084cd49e78b94e4be8541c755a7fa855823ccba4d88c39cf70c9f2f8a4d82e3629699c3c797abf18e7014d37c5341144af
6
+ metadata.gz: 17d75018efc53746ca4b23ba3c7d64d17efe8e5e733367ee03f6f3dc3c586d9745d8ece953a2779d0723fd15d073278dd03a6764ed6ce152a807cdeef9be3862
7
+ data.tar.gz: 4465ccf523a84506f4a3c00e127357407a236fe95cabe2e02a263fae9478ca31bb397a40e478d0f0f9e3e7c33f28f03c496f6e8e6721cad7fd511ff294702123
@@ -12,9 +12,12 @@ module Diva::Combinable
12
12
  # ==== Return
13
13
  # true or false
14
14
  def =~(behavior)
15
- @a.respond_to?(behavior) && @a.__send__(behavior, @b) || @b.respond_to?(behavior) && @b.__send__(behavior, @a)
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 @a.respond_to?(behavior) && @a.__send__(behavior, @b)
28
- yielder << [@b, @a] if @b.respond_to?(behavior) && @b.__send__(behavior, @a)
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
- class EnumerableCombinator < Combinator
41
- def =~(behavior)
42
- @b.any?{|b| !enum(behavior).empty? }
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
- (@a | b).enum(behavior).each(&yielder.method(:<<))
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
- EnumerableCombinator.new(self, other)
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
- Combinator.new(self, other)
103
+ SingleCombinator.new(self, other)
64
104
  end
65
105
  end
66
106
  end
@@ -1,3 +1,3 @@
1
1
  module Diva
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
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.0
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-04 00:00:00.000000000 Z
11
+ date: 2017-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler