Class: GeoipRedis::IpRange
- Inherits:
-
Struct
- Object
- Struct
- GeoipRedis::IpRange
- Defined in:
- lib/geoip_redis/ip_range.rb
Instance Attribute Summary collapse
-
#location_id ⇒ Object
Returns the value of attribute location_id.
-
#max_ip_num ⇒ Object
Returns the value of attribute max_ip_num.
-
#min_ip_num ⇒ Object
Returns the value of attribute min_ip_num.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#location_id ⇒ Object
Returns the value of attribute location_id
4 5 6 |
# File 'lib/geoip_redis/ip_range.rb', line 4 def location_id @location_id end |
#max_ip_num ⇒ Object
Returns the value of attribute max_ip_num
4 5 6 |
# File 'lib/geoip_redis/ip_range.rb', line 4 def max_ip_num @max_ip_num end |
#min_ip_num ⇒ Object
Returns the value of attribute min_ip_num
4 5 6 |
# File 'lib/geoip_redis/ip_range.rb', line 4 def min_ip_num @min_ip_num end |
Class Method Details
.build_from_network(network, location_id) ⇒ Object
6 7 8 9 10 |
# File 'lib/geoip_redis/ip_range.rb', line 6 def self.build_from_network(network, location_id) ip_range = IPAddr.new(network).to_range min_ip_num, max_ip_num = ip_range.first.to_i, ip_range.last.to_i new(location_id, min_ip_num, max_ip_num) end |
.decode(encoded) ⇒ Object
12 13 14 15 16 |
# File 'lib/geoip_redis/ip_range.rb', line 12 def self.decode(encoded) location_id, min_ip_num, max_ip_num = encoded.split(":") min_ip_num, max_ip_num = min_ip_num.to_i, max_ip_num.to_i new(location_id, min_ip_num, max_ip_num) end |
Instance Method Details
#encode ⇒ Object
18 19 20 |
# File 'lib/geoip_redis/ip_range.rb', line 18 def encode "#{location_id}:#{min_ip_num}:#{max_ip_num}" end |
#member?(ip_num) ⇒ Boolean
22 23 24 |
# File 'lib/geoip_redis/ip_range.rb', line 22 def member?(ip_num) (min_ip_num..max_ip_num).member?(ip_num) end |