Class: Pinterest::Image

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

Overview

A object representing a Pinterest image.

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Pinterest::Board

Creates a new image object.

Parameters:

  • data (Hash)

    The data of the new object.



13
14
15
# File 'lib/pinterest/models/image.rb', line 13

def initialize(data)
  @data = data
end

Instance Method Details

#as_json(_ = {}) ⇒ Hash

Serialize the object as a Hash that can be serialized as JSON.

Parameters:

  • _ (Hash) (defaults to: {})

    The options to use to serialize.

Returns:

  • (Hash)

    The serialized object.



45
46
47
# File 'lib/pinterest/models/image.rb', line 45

def as_json(_ = {})
  @data
end

#size(version) ⇒ Hash

Returns the size of a version of the image.

Parameters:

  • version (String)

    The version to inspect.

Returns:

  • (Hash)

    A hash with the :width and :height keys.



28
29
30
31
# File 'lib/pinterest/models/image.rb', line 28

def size(version)
  data = @data.fetch(version.to_s)
  {width: data["width"], height: data["height"]}
end

#url(version) ⇒ String

Returns the URL of a version of the image.

Parameters:

  • version (String)

    The version to inspect.

Returns:

  • (String)

    The version URL.



37
38
39
# File 'lib/pinterest/models/image.rb', line 37

def url(version)
  @data.fetch(version.to_s)["url"]
end

#versionsArray

Returns the possible versions of a image.

Returns:

  • (Array)

    A list of possible version of a image.



20
21
22
# File 'lib/pinterest/models/image.rb', line 20

def versions
  @data.keys
end