Class: Rubyhexagon::Post::Image Private

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

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Class for post file data. This is mostly an abstraction to have data structures in a more Ruby like nature.

Author:

  • Maxine Michalski

Since:

  • 1.0.0

Direct Known Subclasses

Preview, Sample

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(image) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initializer for an Image.

Parameters:

  • image (Hash)

    image information

Options Hash (image):

  • :url (String)

    URI location

  • :ext (String)

    extension string

  • :width (Integer)

    of image

  • :height (Integer)

    of image

  • :size (Integer)

    of image

Author:

  • Maxine Michalski

Since:

  • 1.0.0



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/rubyhexagon/post/image.rb', line 55

def initialize(image)
  unless image.is_a?(Hash)
    raise ArgumentError, "#{image.class} is not a Hash"
  end
  if image.keys != %i[url ext width height size]
    mis = %i[url ext width height size] - image.keys
    raise ArgumentError, "Missing key#{mis.count > 1 ? 's' : ''}: #{mis}"
  end
  image.each do |k, v|
    if %i[ext width height size].include?(k)
      instance_variable_set("@#{k}".to_sym, v)
    elsif k == :url
      @url = URI.parse(v)
    end
  end
end

Instance Attribute Details

#extString (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns extension of file.

Returns:

  • (String)

    extension of file

Since:

  • 1.0.0



32
33
34
# File 'lib/rubyhexagon/post/image.rb', line 32

def ext
  @ext
end

#heightInteger (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns image/video height.

Returns:

  • (Integer)

    image/video height

Since:

  • 1.0.0



38
39
40
# File 'lib/rubyhexagon/post/image.rb', line 38

def height
  @height
end

#sizeInteger (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns file size in bytes.

Returns:

  • (Integer)

    file size in bytes

Since:

  • 1.0.0



41
42
43
# File 'lib/rubyhexagon/post/image.rb', line 41

def size
  @size
end

#urlURI (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns url of file.

Returns:

  • (URI)

    url of file

Since:

  • 1.0.0



29
30
31
# File 'lib/rubyhexagon/post/image.rb', line 29

def url
  @url
end

#widthInteger (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns image/video width.

Returns:

  • (Integer)

    image/video width

Since:

  • 1.0.0



35
36
37
# File 'lib/rubyhexagon/post/image.rb', line 35

def width
  @width
end

Instance Method Details

#==(other) ⇒ TrueClass, FalseClass

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Comparison method to comapre two Image objects (and sub class objects)

Returns:

  • (TrueClass, FalseClass)

Author:

  • Maxine Michalski

Since:

  • 1.0.0



95
96
97
# File 'lib/rubyhexagon/post/image.rb', line 95

def ==(other)
  other.is_a?(Image) && @url == other.url && @size == other.size
end

#aspect_ratioFloat

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

A convenient function to return the aspect ratio of a given image.

Returns:

  • (Float)

Author:

  • Maxine Michalski

Since:

  • 1.0.0



86
87
88
# File 'lib/rubyhexagon/post/image.rb', line 86

def aspect_ratio
  @width / @height.to_f
end

#resolutionArray<Integer>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

A convenient function to return both width and height.

Returns:

  • (Array<Integer>)

Author:

  • Maxine Michalski

Since:

  • 1.0.0



77
78
79
# File 'lib/rubyhexagon/post/image.rb', line 77

def resolution
  [@width, @height]
end