Class: Pokeedex::Pokemon::Scrapper::Parsers::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/pokeedex/pokemon/scrapper/parsers/base.rb

Overview

Base class for the Pokemon parser. It holds the response and the methods to parse the response and return the Pokemon attributes from a HTML response

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Base

Returns a new instance of Base.



17
18
19
# File 'lib/pokeedex/pokemon/scrapper/parsers/base.rb', line 17

def initialize(response)
  @response = response
end

Instance Attribute Details

#responseObject (readonly)

Response from the Pokemon::Pokemon::Scrapper::Fetcher::Base website (HTML response) to parse



15
16
17
# File 'lib/pokeedex/pokemon/scrapper/parsers/base.rb', line 15

def response
  @response
end

Instance Method Details

#as_jsonHash

Return the Pokemon attributes as a JSON object

Returns:

  • (Hash)

    the Pokemon attributes as a JSON object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/pokeedex/pokemon/scrapper/parsers/base.rb', line 24

def as_json(*)
  {
    number: number,
    name: name,
    description: description,
    hight: hight,
    weight: weight,
    category: category,
    abilities: abilities,
    gender: gender,
    types: types,
    weakness: weakness,
    stats: stats
  }
end