Class: IceAndFireApi::Character
- Inherits:
-
Object
- Object
- IceAndFireApi::Character
- Defined in:
- lib/ice_and_fire_api/character.rb
Instance Attribute Summary collapse
-
#aliases ⇒ Object
readonly
Returns the value of attribute aliases.
-
#allegiances ⇒ Object
readonly
Returns the value of attribute allegiances.
-
#books ⇒ Object
readonly
Returns the value of attribute books.
-
#born ⇒ Object
readonly
Returns the value of attribute born.
-
#culture ⇒ Object
readonly
Returns the value of attribute culture.
-
#died ⇒ Object
readonly
Returns the value of attribute died.
-
#father ⇒ Object
readonly
Returns the value of attribute father.
-
#gender ⇒ Object
readonly
Returns the value of attribute gender.
-
#mother ⇒ Object
readonly
Returns the value of attribute mother.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#played_by ⇒ Object
readonly
Returns the value of attribute played_by.
-
#pov_books ⇒ Object
readonly
Returns the value of attribute pov_books.
-
#spouse ⇒ Object
readonly
Returns the value of attribute spouse.
-
#titles ⇒ Object
readonly
Returns the value of attribute titles.
-
#tv_series ⇒ Object
readonly
Returns the value of attribute tv_series.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(attributes) ⇒ Character
constructor
A new instance of Character.
Constructor Details
#initialize(attributes) ⇒ Character
Returns a new instance of Character.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/ice_and_fire_api/character.rb', line 8 def initialize(attributes) @url = attributes['url'] @name = attributes['name'] @gender = attributes['gender'] @culture = attributes['culture'] @born = attributes['born'] @died = attributes['died'] @titles = attributes['titles'] @aliases = attributes['aliases'] @father = attributes['father'] @mother = attributes['mother'] @spouse = attributes['spouse'] @allegiances = attributes['allegiances'] @books = attributes['books'] @pov_books = attributes['povBooks'] @tv_series = attributes['tvSeries'] @played_by = attributes['playedBy'] end |
Instance Attribute Details
#aliases ⇒ Object (readonly)
Returns the value of attribute aliases.
3 4 5 |
# File 'lib/ice_and_fire_api/character.rb', line 3 def aliases @aliases end |
#allegiances ⇒ Object (readonly)
Returns the value of attribute allegiances.
3 4 5 |
# File 'lib/ice_and_fire_api/character.rb', line 3 def allegiances @allegiances end |
#books ⇒ Object (readonly)
Returns the value of attribute books.
3 4 5 |
# File 'lib/ice_and_fire_api/character.rb', line 3 def books @books end |
#born ⇒ Object (readonly)
Returns the value of attribute born.
3 4 5 |
# File 'lib/ice_and_fire_api/character.rb', line 3 def born @born end |
#culture ⇒ Object (readonly)
Returns the value of attribute culture.
3 4 5 |
# File 'lib/ice_and_fire_api/character.rb', line 3 def culture @culture end |
#died ⇒ Object (readonly)
Returns the value of attribute died.
3 4 5 |
# File 'lib/ice_and_fire_api/character.rb', line 3 def died @died end |
#father ⇒ Object (readonly)
Returns the value of attribute father.
3 4 5 |
# File 'lib/ice_and_fire_api/character.rb', line 3 def father @father end |
#gender ⇒ Object (readonly)
Returns the value of attribute gender.
3 4 5 |
# File 'lib/ice_and_fire_api/character.rb', line 3 def gender @gender end |
#mother ⇒ Object (readonly)
Returns the value of attribute mother.
3 4 5 |
# File 'lib/ice_and_fire_api/character.rb', line 3 def mother @mother end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/ice_and_fire_api/character.rb', line 3 def name @name end |
#played_by ⇒ Object (readonly)
Returns the value of attribute played_by.
3 4 5 |
# File 'lib/ice_and_fire_api/character.rb', line 3 def played_by @played_by end |
#pov_books ⇒ Object (readonly)
Returns the value of attribute pov_books.
3 4 5 |
# File 'lib/ice_and_fire_api/character.rb', line 3 def pov_books @pov_books end |
#spouse ⇒ Object (readonly)
Returns the value of attribute spouse.
3 4 5 |
# File 'lib/ice_and_fire_api/character.rb', line 3 def spouse @spouse end |
#titles ⇒ Object (readonly)
Returns the value of attribute titles.
3 4 5 |
# File 'lib/ice_and_fire_api/character.rb', line 3 def titles @titles end |
#tv_series ⇒ Object (readonly)
Returns the value of attribute tv_series.
3 4 5 |
# File 'lib/ice_and_fire_api/character.rb', line 3 def tv_series @tv_series end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
3 4 5 |
# File 'lib/ice_and_fire_api/character.rb', line 3 def url @url end |
Class Method Details
.find(id) ⇒ Object
27 28 29 30 31 |
# File 'lib/ice_and_fire_api/character.rb', line 27 def self.find(id) response = Faraday.get("#{IceAndFireApi::API_URL}/characters/#{id}") attributes = JSON.parse(response.body) new(attributes) end |
.find_by_name(name) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/ice_and_fire_api/character.rb', line 33 def self.find_by_name(name) name_query = URI.encode_www_form_component(name.to_s) response = Faraday.get("#{IceAndFireApi::API_URL}/characters?name=#{name_query}") attributes_response = JSON.parse(response.body) attributes_array = [] attributes_response.each do |attributes| attributes_array << new(attributes) end attributes_array end |