Class: IpRestriction::IpChecker
- Inherits:
-
Object
- Object
- IpRestriction::IpChecker
- Defined in:
- lib/ip_restriction/ip_checker.rb
Instance Attribute Summary collapse
-
#ranges ⇒ Object
readonly
Returns the value of attribute ranges.
Instance Method Summary collapse
- #allowed?(ip) ⇒ Boolean
-
#initialize(ranges) ⇒ IpChecker
constructor
A new instance of IpChecker.
Constructor Details
#initialize(ranges) ⇒ IpChecker
Returns a new instance of IpChecker.
7 8 9 |
# File 'lib/ip_restriction/ip_checker.rb', line 7 def initialize(ranges) @ranges = ranges end |
Instance Attribute Details
#ranges ⇒ Object (readonly)
Returns the value of attribute ranges.
5 6 7 |
# File 'lib/ip_restriction/ip_checker.rb', line 5 def ranges @ranges end |
Instance Method Details
#allowed?(ip) ⇒ Boolean
11 12 13 14 15 |
# File 'lib/ip_restriction/ip_checker.rb', line 11 def allowed?(ip) ranges.any? do |range_or_ip| IPAddr.new(range_or_ip).include?(IPAddr.new(ip)) end end |