Class: ScrapeGot::Houses

Inherits:
Object
  • Object
show all
Defined in:
lib/scrape_got/houses.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Houses

Returns a new instance of Houses.



17
18
19
20
21
22
# File 'lib/scrape_got/houses.rb', line 17

def initialize(attributes = {})
  @name = attributes["name"]
  @coat = attributes["coatOfArms"]
  @region = attributes["region"]
  @words = attributes["words"]
end

Instance Attribute Details

#coatObject

Returns the value of attribute coat.



4
5
6
# File 'lib/scrape_got/houses.rb', line 4

def coat
  @coat
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/scrape_got/houses.rb', line 4

def name
  @name
end

#regionObject

Returns the value of attribute region.



4
5
6
# File 'lib/scrape_got/houses.rb', line 4

def region
  @region
end

#wordsObject

Returns the value of attribute words.



4
5
6
# File 'lib/scrape_got/houses.rb', line 4

def words
  @words
end

Class Method Details

.all_housesObject



7
8
9
# File 'lib/scrape_got/houses.rb', line 7

def self.all_houses
  @@all_houses ||= self.load_houses
end

.load_housesObject



11
12
13
14
15
# File 'lib/scrape_got/houses.rb', line 11

def self.load_houses
  API.get_houses.collect do |houses_hash|
    Houses.new(houses_hash)
  end
end


24
25
26
27
28
29
30
31
# File 'lib/scrape_got/houses.rb', line 24

def self.print_houses
  Houses.all_houses.each.with_index(1) do |house, index|
    puts "#{index} #{house.name}: #{house.words}"
    puts "Coat of Arms: #{house.coat}"
    puts "Region: #{house.region}"
    puts "-----------------------------------".colorize(:light_yellow)
  end
end