Class: Rubyhexagon::Post::Image Private
- Inherits:
-
Object
- Object
- Rubyhexagon::Post::Image
- 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.
Instance Attribute Summary collapse
-
#ext ⇒ String
readonly
private
Extension of file.
-
#height ⇒ Integer
readonly
private
Image/video height.
-
#size ⇒ Integer
readonly
private
File size in bytes.
-
#url ⇒ URI
readonly
private
Url of file.
-
#width ⇒ Integer
readonly
private
Image/video width.
Instance Method Summary collapse
-
#==(other) ⇒ TrueClass, FalseClass
private
Comparison method to comapre two Image objects (and sub class objects).
-
#aspect_ratio ⇒ Float
private
A convenient function to return the aspect ratio of a given image.
-
#initialize(image) ⇒ Object
constructor
private
Initializer for an Image.
-
#resolution ⇒ Array<Integer>
private
A convenient function to return both width and height.
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.
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
#ext ⇒ String (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.
32 33 34 |
# File 'lib/rubyhexagon/post/image.rb', line 32 def ext @ext end |
#height ⇒ Integer (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.
38 39 40 |
# File 'lib/rubyhexagon/post/image.rb', line 38 def height @height end |
#size ⇒ Integer (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.
41 42 43 |
# File 'lib/rubyhexagon/post/image.rb', line 41 def size @size end |
#url ⇒ URI (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.
29 30 31 |
# File 'lib/rubyhexagon/post/image.rb', line 29 def url @url end |
#width ⇒ Integer (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.
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)
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_ratio ⇒ Float
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.
86 87 88 |
# File 'lib/rubyhexagon/post/image.rb', line 86 def aspect_ratio @width / @height.to_f end |
#resolution ⇒ Array<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.
77 78 79 |
# File 'lib/rubyhexagon/post/image.rb', line 77 def resolution [@width, @height] end |