Sha256: 4d1f94c369181653c3f78160d720c8d7ea71f5a0f378a0d44cff26d89a9f7424
Contents?: true
Size: 1.48 KB
Versions: 3
Compression:
Stored size: 1.48 KB
Contents
# frozen_string_literal: true require 'uri' module PhoneSites module GsmArena class Manufacturer < PhoneSites::Manufacturer def parse(data, attr_name) case attr_name when :name data.children.select { |x| x.is_a?(Nokogiri::XML::Text) }.first.text when :url data.get_attribute("href") when :count data.children.select { |x| x.is_a?(Nokogiri::XML::Element) && x.name == "span" } .first.children.first.text.split(" ").first.to_i else raise NotImplementedError end end def models pages_count.times.inject([]) do |sum, i| sum.concat(self.class.models_response.perform(self, build_url(i))) end end def pages_count (count.to_f / PhoneSites::GsmArena::PhoneModel::ITEMS_PER_PAGE).ceil end def build_url(page) url_end = page.zero? ? url : url.gsub(".php", "-#{page}.php") URI.join(self.class.base_url, url_end).to_s end def self.manufacturer_response GsmArena::ManufacturersListResponse.new end def self.models_response PhoneSites::GsmArena::ModelListResponse.new end def self.manufacturers_url ::URI.join(GsmArena::BASE_URL, GsmArena::MANUFACTURERS_URL).to_s end def self.base_url GsmArena::BASE_URL end def self.all url = manufacturers_url manufacturer_response.perform(url) end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
phone_sites-0.0.5 | lib/phone_sites/gsm_arena/manufacturer.rb |
phone_sites-0.0.5a | lib/phone_sites/gsm_arena/manufacturer.rb |
phone_sites-0.0.4 | lib/phone_sites/gsm_arena/manufacturer.rb |