Class: Onebox::Movie
- Inherits:
-
Object
- Object
- Onebox::Movie
- Defined in:
- lib/onebox/movie.rb
Instance Method Summary collapse
- #description ⇒ Object
- #duration ⇒ Object
- #genres ⇒ Object
- #image ⇒ Object
-
#initialize(json_ld_data) ⇒ Movie
constructor
A new instance of Movie.
- #name ⇒ Object
- #rating ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(json_ld_data) ⇒ Movie
Returns a new instance of Movie.
5 6 7 |
# File 'lib/onebox/movie.rb', line 5 def initialize(json_ld_data) @json_ld_data = json_ld_data end |
Instance Method Details
#description ⇒ Object
17 18 19 |
# File 'lib/onebox/movie.rb', line 17 def description @json_ld_data["description"] end |
#duration ⇒ Object
29 30 31 32 33 |
# File 'lib/onebox/movie.rb', line 29 def duration return nil unless @json_ld_data["duration"] Time.parse(@json_ld_data["duration"]).strftime "%H:%M" end |
#genres ⇒ Object
25 26 27 |
# File 'lib/onebox/movie.rb', line 25 def genres @json_ld_data["genre"] end |
#image ⇒ Object
13 14 15 |
# File 'lib/onebox/movie.rb', line 13 def image @json_ld_data["image"] end |
#name ⇒ Object
9 10 11 |
# File 'lib/onebox/movie.rb', line 9 def name @json_ld_data["name"] end |
#rating ⇒ Object
21 22 23 |
# File 'lib/onebox/movie.rb', line 21 def @json_ld_data.dig("aggregateRating", "ratingValue") end |
#to_h ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/onebox/movie.rb', line 35 def to_h { name: name, image: image, description: description, rating: , genres: genres, duration: duration, } end |