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
Image file extension.
-
#height ⇒ Integer
readonly
private
Image height.
-
#size ⇒ Integer
readonly
private
Image file size.
-
#url ⇒ URI
readonly
private
Image url.
-
#width ⇒ Integer
readonly
private
Image 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.
-
#to_hash ⇒ Hash
private
Turn object into a hash representation of itself.
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
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/rubyhexagon/post/image.rb', line 60 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.
Image file extension
34 35 36 |
# File 'lib/rubyhexagon/post/image.rb', line 34 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.
Image height
42 43 44 |
# File 'lib/rubyhexagon/post/image.rb', line 42 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.
Image file size
46 47 48 |
# File 'lib/rubyhexagon/post/image.rb', line 46 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.
Image url
30 31 32 |
# File 'lib/rubyhexagon/post/image.rb', line 30 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.
Image width
38 39 40 |
# File 'lib/rubyhexagon/post/image.rb', line 38 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)
102 103 104 |
# File 'lib/rubyhexagon/post/image.rb', line 102 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
91 92 93 |
# File 'lib/rubyhexagon/post/image.rb', line 91 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
82 83 84 |
# File 'lib/rubyhexagon/post/image.rb', line 82 def resolution [@width, @height] end |
#to_hash ⇒ Hash
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.
Turn object into a hash representation of itself
113 114 115 116 117 118 119 |
# File 'lib/rubyhexagon/post/image.rb', line 113 def to_hash hash = {} instance_variables.each do |i| hash.store(i.to_s.sub(/^@/, '').to_sym, instance_variable_get(i)) end hash end |