-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccount_specs.rb
62 lines (52 loc) · 1.25 KB
/
account_specs.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
module AccountSpecs
class Spec
def or(other)
OrOperatorSpec.new(self, other)
end
def and(other)
AndOperatorSpec.new(self, other)
end
def satisfied_by?(transaction)
true
end
end
class CompositeSpec < Spec
def initialize(a_spec, another_spec)
@a_spec = a_spec
@another_spec = another_spec
end
end
class OrOperatorSpec < CompositeSpec
def satisfied_by?(transaction)
@a_spec.satisfied_by?(transaction) || @another_spec.satisfied_by?(transaction)
end
end
class AndOperatorSpec < CompositeSpec
def satisfied_by?(transaction)
@a_spec.satisfied_by?(transaction) && @another_spec.satisfied_by?(transaction)
end
end
class PayrollSpec < Spec
def satisfied_by?(transaction)
transaction[:information] =~ /payroll/
end
end
class WithdrawalSpec < Spec
def satisfied_by?(transaction)
transaction[:information] =~ /withdrawal/
end
end
class FeesSpec < Spec
def satisfied_by?(transaction)
transaction[:information] =~ /fees/
end
end
class AmountGreaterThanSpec < Spec
def initialize(threshold)
@threshold = threshold
end
def satisfied_by?(transaction)
transaction[:amount] >= @threshold
end
end
end