Module: TomatoPower::Parser
- Defined in:
- lib/tomato_power/helpers/parsers.rb
Overview
Handles parsing of the returned results from an API call.
Class Method Summary collapse
-
.parse(json) ⇒ Object
Parses a json object into a Tomato Power object.
-
.parse_cast(abridged_cast) ⇒ Object
Parses TomatoPower::Movie abridged cast members.
-
.parse_posters(poster_types) ⇒ TomatoPower::Poster
Parses TomatoPower::Movie posters.
Class Method Details
.parse(json) ⇒ Object
Parses a json object into a Tomato Power object.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/tomato_power/helpers/parsers.rb', line 8 def self.parse json payload =[] if json["movies"] json["movies"].each do |movie| payload << Movie.new(movie) end elsif json["cast"] json["cast"].each do |actor| payload << Actor.new(actor) end elsif json["clips"] json["clips"].each do |clip| payload << Clip.new(clip) end elsif json["reviews"] json["reviews"].each do |review| payload << Review.new(review) end else payload << Movie.new(json) end payload end |
.parse_cast(abridged_cast) ⇒ Object
Parses TomatoPower::Movie abridged cast members
44 45 46 47 48 49 50 |
# File 'lib/tomato_power/helpers/parsers.rb', line 44 def self.parse_cast abridged_cast parsed_cast =[] abridged_cast.each do |cast_member| parsed_cast << Actor.new( cast_member ) end parsed_cast end |
.parse_posters(poster_types) ⇒ TomatoPower::Poster
Parses TomatoPower::Movie posters
36 37 38 |
# File 'lib/tomato_power/helpers/parsers.rb', line 36 def self.parse_posters poster_types Poster.new(poster_types) end |