class PhoneSites::GsmArena::ModelInfoResponse
Public Instance Methods
perform(url, method = 'get', options = {})
click to toggle source
Calls superclass method
PhoneSites::BaseResponse#perform
# File lib/phone_sites/gsm_arena/model_info_response.rb, line 5 def perform(url, method = 'get', options = {}) response = super(url, method, options) body = Nokogiri::HTML(response.body) body.css('#specs-list table tr td') .map(&:text) .each_slice(2) .each_with_object({}) do |(key, value), hash| properties = normalize_property(key, value) hash.merge!(properties) if valid?(key) end end
Private Instance Methods
normalize_property(key, value)
click to toggle source
# File lib/phone_sites/gsm_arena/model_info_response.rb, line 33 def normalize_property(key, value) { key.strip => normalize_property_value(value) } end
normalize_property_value(value)
click to toggle source
# File lib/phone_sites/gsm_arena/model_info_response.rb, line 19 def normalize_property_value(value) val = value.tr("\r\n", '').strip case val when "Yes" true when "No" false when "-" nil else val end end
valid?(key)
click to toggle source
# File lib/phone_sites/gsm_arena/model_info_response.rb, line 37 def valid?(key) key.length != 1 end