-
Notifications
You must be signed in to change notification settings - Fork 0
/
validations.rb
72 lines (55 loc) · 1.42 KB
/
validations.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
63
64
65
66
67
68
69
70
71
72
module Validations
class CustomerSuccessValidation
LIMIT_SCORE = 10000
LIMIT_ID = 1000
LIMIT_SIZE = 1000
def initialize(customer_success:, away_customer_success: [])
@id = customer_success[:id]
@score = customer_success[:score]
@away_customer_success = away_customer_success
end
def valid?
id_inside_limit? &&
score_inside_limit? &&
available_customer_success?
end
def self.allowed_size?(customer_success_list:)
customer_success_list.size < LIMIT_SIZE
end
private
attr_reader :id, :score, :away_customer_success
def id_inside_limit?
id.positive? && id < LIMIT_ID
end
def score_inside_limit?
score.positive? && score < LIMIT_SCORE
end
def available_customer_success?
return true if away_customer_success.empty?
!away_customer_success.include?(id)
end
end
class CustomerValidation
LIMIT_SCORE = 100000
LIMIT_ID = 1000000
LIMIT_SIZE = 1000000
def initialize(customer:)
@id = customer[:id]
@score = customer[:score]
end
def valid?
id_inside_limit? && score_inside_limit?
end
def self.allowed_size?(customers:)
customers.size < LIMIT_SIZE
end
private
attr_reader :id, :score
def id_inside_limit?
id.positive? && id < LIMIT_ID
end
def score_inside_limit?
score.positive? && score < LIMIT_SCORE
end
end
end