Class: TheTvDb::Api::Image

Inherits:
Object show all
Defined in:
lib/the_tv_db/api/image.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input_xml_node) ⇒ Image

Returns a new instance of Image.



10
11
12
13
# File 'lib/the_tv_db/api/image.rb', line 10

def initialize(input_xml_node)
  @xml_node = input_xml_node
  self
end

Instance Attribute Details

#xml_nodeObject

Returns the value of attribute xml_node.



8
9
10
# File 'lib/the_tv_db/api/image.rb', line 8

def xml_node
  @xml_node
end

Instance Method Details

#aspectObject



63
64
65
66
67
68
# File 'lib/the_tv_db/api/image.rb', line 63

def aspect
  if height and width
    gcd = height.gcd(width)
    [(width / gcd), (height / gcd)]
  end
end

#heightObject



55
56
57
58
59
60
61
# File 'lib/the_tv_db/api/image.rb', line 55

def height
  if subtype_looks_like_dimensions? 
    height_from_subtype 
  elsif can_read_image_file?
    image_geometry[:height]
  end
end

#languageObject



23
24
25
# File 'lib/the_tv_db/api/image.rb', line 23

def language
  xpath('.//Language').try(:to_sym)
end

#network_idObject



35
36
37
# File 'lib/the_tv_db/api/image.rb', line 35

def network_id
  xpath('.//id').to_i
end

#pathObject



31
32
33
# File 'lib/the_tv_db/api/image.rb', line 31

def path
  "#{TheTvDb::Api::Mirrors.all.first}/banners/#{xpath('.//BannerPath')}"
end

#pixelsObject



43
44
45
# File 'lib/the_tv_db/api/image.rb', line 43

def pixels
  (width * height).to_i rescue 0
end

#ratingObject



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

def rating
  xpath('.//Rating').try(:to_f).try(:round, 1)
end

#sub_typeObject



27
28
29
# File 'lib/the_tv_db/api/image.rb', line 27

def sub_type
  xpath('.//BannerType2').try(:to_sym) unless subtype_looks_like_dimensions?
end

#typeObject



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

def type
  xpath('.//BannerType').try(:to_sym)
end

#widescreen?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/the_tv_db/api/image.rb', line 39

def widescreen?
  aspect && (aspect[0].to_f / aspect[1] >= (16.to_f / 9 ))
end

#widthObject



47
48
49
50
51
52
53
# File 'lib/the_tv_db/api/image.rb', line 47

def width
  if subtype_looks_like_dimensions?
    width_from_subtype
  elsif can_read_image_file?
    image_geometry[:width]
  end
end