Class: TMDBParty::Image

Inherits:
Object
  • Object
show all
Defined in:
lib/tmdb_party/image.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Image

Returns a new instance of Image.



3
4
5
# File 'lib/tmdb_party/image.rb', line 3

def initialize(attributes)
  @attributes = attributes
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args, &block) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/tmdb_party/image.rb', line 23

def method_missing(*args, &block)
  if args.first.to_s =~ /\A(.*)_url\Z/
    @attributes["#{$1}_url"]
  else
    super
  end
end

Class Method Details

.parse(data) ⇒ Object



32
33
34
35
36
# File 'lib/tmdb_party/image.rb', line 32

def parse(data)
  data.map { |row| row['image'] }.group_by { |row| row['id'] }.map do |id, images|
    Image.new(reduce_images(images))
  end
end

Instance Method Details

#idObject



7
8
9
# File 'lib/tmdb_party/image.rb', line 7

def id
  @attributes['id']
end

#sizesObject



15
16
17
# File 'lib/tmdb_party/image.rb', line 15

def sizes
  @attributes['sizes'].map { |size| size.downcase.to_sym }.to_set
end

#typeObject



11
12
13
# File 'lib/tmdb_party/image.rb', line 11

def type
  @attributes['type'].downcase.to_sym
end

#urlObject



19
20
21
# File 'lib/tmdb_party/image.rb', line 19

def url
  original_url
end