Class: Anime

Inherits:
Helpers show all
Defined in:
lib/foxit/objects.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Helpers

#objects_to_hash, #to_hash

Constructor Details

#initialize(data) ⇒ Anime

Returns a new instance of Anime.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/foxit/objects.rb', line 27

def initialize data
  attributes = data['attributes']
  @id = data['id'].to_i
  @slug = attributes['slug']
  @synopsis = attributes['synopsis']
  @title = attributes['canonicalTitle']
  @avg_rating = attributes['averageRating'].to_f  # TODO: need to handle nil values?

  
  rf_int = {}
  # mongodb needs string keys anyway, so k.to_i redundant...

  attributes['ratingFrequencies'].each_pair { | k, v | rf_int[k.to_i] = v.to_i }
  @rating_freq = rf_int

  @n_users = attributes['userCount'].to_i
  @n_favourites = attributes['favouritesCount'].to_i
  @start_date = attributes['startDate']
  @end_date = attributes['endDate']
  @rank_popularity = attributes['popularityRank'].to_i
  @rank_rating = attributes['ratingRank'].to_i
  @subtype = attributes['subtype']
  @showtype = attributes['showType']
  @nsfw = attributes['nsfw']  # TODO: convert to bool?

end

Instance Attribute Details

#avg_ratingObject (readonly)

Returns the value of attribute avg_rating.



23
24
25
# File 'lib/foxit/objects.rb', line 23

def avg_rating
  @avg_rating
end

#end_dateObject (readonly)

Returns the value of attribute end_date.



23
24
25
# File 'lib/foxit/objects.rb', line 23

def end_date
  @end_date
end

#idObject (readonly)

Returns the value of attribute id.



23
24
25
# File 'lib/foxit/objects.rb', line 23

def id
  @id
end

#n_favouritesObject (readonly)

Returns the value of attribute n_favourites.



23
24
25
# File 'lib/foxit/objects.rb', line 23

def n_favourites
  @n_favourites
end

#n_usersObject (readonly)

Returns the value of attribute n_users.



23
24
25
# File 'lib/foxit/objects.rb', line 23

def n_users
  @n_users
end

#nsfwObject (readonly)

Returns the value of attribute nsfw.



23
24
25
# File 'lib/foxit/objects.rb', line 23

def nsfw
  @nsfw
end

#rank_popularityObject (readonly)

Returns the value of attribute rank_popularity.



23
24
25
# File 'lib/foxit/objects.rb', line 23

def rank_popularity
  @rank_popularity
end

#rank_ratingObject (readonly)

Returns the value of attribute rank_rating.



23
24
25
# File 'lib/foxit/objects.rb', line 23

def rank_rating
  @rank_rating
end

#rating_freqObject (readonly)

Returns the value of attribute rating_freq.



23
24
25
# File 'lib/foxit/objects.rb', line 23

def rating_freq
  @rating_freq
end

#slugObject (readonly)

Returns the value of attribute slug.



23
24
25
# File 'lib/foxit/objects.rb', line 23

def slug
  @slug
end

#start_dateObject (readonly)

Returns the value of attribute start_date.



23
24
25
# File 'lib/foxit/objects.rb', line 23

def start_date
  @start_date
end

#subtypeObject (readonly)

Returns the value of attribute subtype.



23
24
25
# File 'lib/foxit/objects.rb', line 23

def subtype
  @subtype
end

#synopsisObject (readonly)

Returns the value of attribute synopsis.



23
24
25
# File 'lib/foxit/objects.rb', line 23

def synopsis
  @synopsis
end

#titleObject (readonly)

Returns the value of attribute title.



23
24
25
# File 'lib/foxit/objects.rb', line 23

def title
  @title
end