Class: Nytimes::Articles::Thumbnail

Inherits:
Object
  • Object
show all
Defined in:
lib/nytimes_articles/thumbnail.rb

Overview

If requested in :fields for an article search, some articles are returned with a matching thumbnail image. The several thumbnail fields are collected together into a single Thumbnail instance for your convenience.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, width, height) ⇒ Thumbnail

Returns a new instance of Thumbnail.



9
10
11
12
13
# File 'lib/nytimes_articles/thumbnail.rb', line 9

def initialize(url, width, height)
	@url = url
	@width = width
	@height = height
end

Instance Attribute Details

#heightObject (readonly)

Returns the value of attribute height.



7
8
9
# File 'lib/nytimes_articles/thumbnail.rb', line 7

def height
  @height
end

#urlObject (readonly)

Returns the value of attribute url.



7
8
9
# File 'lib/nytimes_articles/thumbnail.rb', line 7

def url
  @url
end

#widthObject (readonly)

Returns the value of attribute width.



7
8
9
# File 'lib/nytimes_articles/thumbnail.rb', line 7

def width
  @width
end

Class Method Details

.init_from_api(api_hash) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/nytimes_articles/thumbnail.rb', line 15

def self.init_from_api(api_hash)
	return nil unless !api_hash.nil? && api_hash['small_image_url']
	
	unless api_hash['small_image_width'].nil?
		width = api_hash['small_image_width'].to_i
	end
	
	unless api_hash['small_image_height'].nil?
		height = api_hash['small_image_height'].to_i
	end
	
	new(api_hash['small_image_url'], width, height)
end