Sha256: 63517e61fd395ab81f68b69d0cc10640055ea5cd0876c58b453c6c51459b7b62
Contents?: true
Size: 995 Bytes
Versions: 1
Compression:
Stored size: 995 Bytes
Contents
# 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
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
phone_sites-0.1.2 | lib/phone_sites/gsm_arena/model_info_response.rb |