class Maxmind::Response
Constants
- ATTRIBUTE_MAP
Attributes
attributes[RW]
body[R]
http_code[R]
Public Class Methods
new(response = nil, http_code = nil)
click to toggle source
# File lib/maxmind/response.rb, line 14 def initialize(response = nil, http_code = nil) raise ArgumentError, 'Missing response string' unless response @body = response @http_code = http_code.to_i if http_code @attributes = {} parse(response) end
Public Instance Methods
attribute_names()
click to toggle source
Returns an array of names for the attributes available on this object sorted alphabetically.
# File lib/maxmind/response.rb, line 36 def attribute_names attributes.keys.sort end
method_missing(meth, *args)
click to toggle source
Calls superclass method
# File lib/maxmind/response.rb, line 40 def method_missing(meth, *args) if meth.to_s[-1, 1] == '?' send(meth.to_s[0..-2]) elsif attributes.has_key?(meth) attributes[meth] else super end end
parse(response)
click to toggle source
# File lib/maxmind/response.rb, line 22 def parse(response) response.split(';').each do |parameter| k, v = parameter.split('=') if ATTRIBUTE_MAP.has_key?(k) set_attribute(ATTRIBUTE_MAP[k], v) else set_attribute(k.gsub(/([A-Z])/, '_\1').downcase, v) end end end
respond_to?(meth)
click to toggle source
Calls superclass method
# File lib/maxmind/response.rb, line 50 def respond_to?(meth) if meth.to_s[-1, 1] == '?' respond_to? meth[0..-2] else super end end
Protected Instance Methods
set_attribute(k, v)
click to toggle source
# File lib/maxmind/response.rb, line 60 def set_attribute(k, v) k = k.to_sym if v.nil? attributes[k] = nil return end v = Integer(v) rescue Float(v) rescue v; case v when 'Yes', 'yes' attributes[k] = true when 'No', 'no' attributes[k] = false else attributes[k] = v end end