Sha256: a276640421f305858487b9fda8b8b6421cafae39600213b0c6e7cde7128afa3d

Contents?: true

Size: 1.36 KB

Versions: 1

Compression:

Stored size: 1.36 KB

Contents

#
# This file is part of the pinterest-ruby gem. Copyright (C) 2017 and above Shogun <shogun@cowtech.it>.
# Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
#

module Pinterest
  # A object representing a Pinterest image.
  class Image
    # Creates a new image object.
    #
    # @param data [Hash] The data of the new object.
    # @return [Pinterest::Board] The new board object.
    def initialize(data)
      @data = data
    end

    # Returns the possible versions of a image.
    #
    # @return [Array] A list of possible version of a image.
    def versions
      @data.keys
    end

    # Returns the size of a version of the image.
    #
    # @param version [String] The version to inspect.
    # @return [Hash] A hash with the `:width` and `:height` keys.
    def size(version)
      data = @data.fetch(version.to_s)
      {width: data["width"], height: data["height"]}
    end

    # Returns the URL of a version of the image.
    #
    # @param version [String] The version to inspect.
    # @return [String] The version URL.
    def url(version)
      @data.fetch(version.to_s)["url"]
    end

    # Serialize the object as a Hash that can be serialized as JSON.
    #
    # @param _ [Hash] The options to use to serialize.
    # @return [Hash] The serialized object.
    def as_json(_ = {})
      @data
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pinterest-ruby-1.0.0 lib/pinterest/models/image.rb