Class: MyAnimeList::Serializer
- Inherits:
-
Object
- Object
- MyAnimeList::Serializer
- Defined in:
- lib/myanimelist/serializer.rb
Instance Method Summary collapse
- #fetch ⇒ Object
-
#initialize(data, type) ⇒ Serializer
constructor
A new instance of Serializer.
- #is_array?(data) ⇒ Boolean
- #serialize_data ⇒ Object
Constructor Details
#initialize(data, type) ⇒ Serializer
Returns a new instance of Serializer.
3 4 5 6 |
# File 'lib/myanimelist/serializer.rb', line 3 def initialize(data, type) @type = type @animes = data || [] end |
Instance Method Details
#fetch ⇒ Object
8 9 10 |
# File 'lib/myanimelist/serializer.rb', line 8 def fetch serialize_data end |
#is_array?(data) ⇒ Boolean
24 25 26 |
# File 'lib/myanimelist/serializer.rb', line 24 def is_array?(data) data.is_a? Array end |
#serialize_data ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/myanimelist/serializer.rb', line 12 def serialize_data return @animes if is_array? @animes collection = [] data = @animes[@type]['entry'] if is_array? data collection += data else collection << data end end |