Reputation: 111040
I have the following:
EXCLUSION_DOMAINS = %w[
example.com
test.com
asdf.com
yahoo.
gmail
]
Some of these exclusion domains have the full address like.com, others just a high level domain for generic matching.
Given this list, and given a value, how can I determine if the value matches one of the exclusion domains w rails 3?
Thanks
Upvotes: 0
Views: 69
Reputation: 20036
I think you can simply use string.split(".").first
Even if there is not "." (e.g. gmail instead of gmail.) you will still get the "gmail"
Upvotes: 0
Reputation: 21
I solve this problem by using that:
my_domain = "gmail.com.br"
EXCLUSION_DOMAINS.any? { |d| my_domain =~ /#{d}/ }
Upvotes: 2
Reputation: 4807
def excluded?(value)
EXCLUSION_DOMAINS.any? { |domain| value.include? domain }
end
Upvotes: 2