Class: IceAndFireApi::House

Inherits:
Object
  • Object
show all
Defined in:
lib/ice_and_fire_api/house.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ House

Returns a new instance of House.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ice_and_fire_api/house.rb', line 9

def initialize(attributes)
  @url = attributes['url']
  @name = attributes['name']
  @region = attributes['region']
  @coat_of_arms = attributes['coatOfArms']
  @words = attributes['words']
  @titles = attributes['titles']
  @seats = attributes['seats']
  @current_lord = attributes['currentLord']
  @heir = attributes['heir']
  @overlord = attributes['overlord']
  @founded = attributes['founded']
  @founder = attributes['founder']
  @died_out = attributes['diedOut']
  @ancestral_weapons = attributes['ancestralWeapons']
  @cadet_branches = attributes['cadetBranches']
  @sworn_members = attributes['swornMembers']
end

Instance Attribute Details

#ancestral_weaponsObject (readonly)

Returns the value of attribute ancestral_weapons.



3
4
5
# File 'lib/ice_and_fire_api/house.rb', line 3

def ancestral_weapons
  @ancestral_weapons
end

#cadet_branchesObject (readonly)

Returns the value of attribute cadet_branches.



3
4
5
# File 'lib/ice_and_fire_api/house.rb', line 3

def cadet_branches
  @cadet_branches
end

#coat_of_armsObject (readonly)

Returns the value of attribute coat_of_arms.



3
4
5
# File 'lib/ice_and_fire_api/house.rb', line 3

def coat_of_arms
  @coat_of_arms
end

#current_lordObject (readonly)

Returns the value of attribute current_lord.



3
4
5
# File 'lib/ice_and_fire_api/house.rb', line 3

def current_lord
  @current_lord
end

#died_outObject (readonly)

Returns the value of attribute died_out.



3
4
5
# File 'lib/ice_and_fire_api/house.rb', line 3

def died_out
  @died_out
end

#foundedObject (readonly)

Returns the value of attribute founded.



3
4
5
# File 'lib/ice_and_fire_api/house.rb', line 3

def founded
  @founded
end

#founderObject (readonly)

Returns the value of attribute founder.



3
4
5
# File 'lib/ice_and_fire_api/house.rb', line 3

def founder
  @founder
end

#heirObject (readonly)

Returns the value of attribute heir.



3
4
5
# File 'lib/ice_and_fire_api/house.rb', line 3

def heir
  @heir
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/ice_and_fire_api/house.rb', line 3

def name
  @name
end

#overlordObject (readonly)

Returns the value of attribute overlord.



3
4
5
# File 'lib/ice_and_fire_api/house.rb', line 3

def overlord
  @overlord
end

#regionObject (readonly)

Returns the value of attribute region.



3
4
5
# File 'lib/ice_and_fire_api/house.rb', line 3

def region
  @region
end

#seatsObject (readonly)

Returns the value of attribute seats.



3
4
5
# File 'lib/ice_and_fire_api/house.rb', line 3

def seats
  @seats
end

#sworn_membersObject (readonly)

Returns the value of attribute sworn_members.



3
4
5
# File 'lib/ice_and_fire_api/house.rb', line 3

def sworn_members
  @sworn_members
end

#titlesObject (readonly)

Returns the value of attribute titles.



3
4
5
# File 'lib/ice_and_fire_api/house.rb', line 3

def titles
  @titles
end

#urlObject (readonly)

Returns the value of attribute url.



3
4
5
# File 'lib/ice_and_fire_api/house.rb', line 3

def url
  @url
end

#wordsObject (readonly)

Returns the value of attribute words.



3
4
5
# File 'lib/ice_and_fire_api/house.rb', line 3

def words
  @words
end

Class Method Details

.find(id) ⇒ Object



28
29
30
31
32
# File 'lib/ice_and_fire_api/house.rb', line 28

def self.find(id)
  response = Faraday.get("#{IceAndFireApi::API_URL}/houses/#{id}")
  attributes = JSON.parse(response.body)
  new(attributes)
end

.find_by_name(name) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/ice_and_fire_api/house.rb', line 34

def self.find_by_name(name)
  name_query = URI.encode_www_form_component(name.to_s)
  response = Faraday.get("#{IceAndFireApi::API_URL}/houses?name=#{name_query}")
  attributes_response = JSON.parse(response.body)
  attributes_array = []
  attributes_response.each do |attributes|
    attributes_array << new(attributes)
  end
  attributes_array
end