Sha256: 901b9f8a5ff15dcc942d60f12128a8b18eecca4b2a39c18557dee96055d18025

Contents?: true

Size: 1.16 KB

Versions: 2

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true

require_relative 'base'

module Pokeedex # :nodoc:
  module Pokemon # :nodoc:
    module Scrapper # :nodoc:
      ##
      # The Pokedex scrapper. It holds the methods to crawl the Pokedex data from the Pokemon website
      class Pokedex < Base
        ##
        # Find by number or name the Pokemon data from the Pokemon website
        attr_reader :number_or_name

        def initialize(number_or_name:)
          @number_or_name = number_or_name
        end

        ##
        # Return the URL to crawl the Pokemon data
        # If you number_or_name is 'pikachu' then the URL will be 'https://www.pokemon.com/el/pokedex/pikachu'
        # @return [String]
        def url
          "#{BASE_URI}/#{number_or_name}"
        end

        ##
        # Crawl the Pokemon data from the Pokemon website
        # @return [Hash]
        def crawl
          parser.as_json
        end

        private

        def parser
          Parsers::Base.new(remote_content)
        end

        def remote_content
          fetcher.content
        end

        def fetcher
          @fetcher ||= Fetchers::Base.new(url: url)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pokeedex-0.1.5 lib/pokeedex/pokemon/scrapper/pokedex.rb
pokeedex-0.1.0 lib/pokeedex/pokemon/scrapper/pokedex.rb