# frozen_string_literal: true module PhoneSites module GsmArena class ModelInfoResponse < ::PhoneSites::BaseResponse 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 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 def normalize_property(key, value) { key.strip => normalize_property_value(value) } end def valid?(key) key.length != 1 end end end end