Class: Rubyhexagon::Post::File Private
- Inherits:
-
Object
- Object
- Rubyhexagon::Post::File
- Defined in:
- lib/rubyhexagon/post/file.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
File file extension.
-
#height ⇒ Integer
readonly
private
File height.
-
#md5 ⇒ String
readonly
private
File MD5 hash string.
-
#size ⇒ Integer
readonly
private
File size.
-
#url ⇒ URI
readonly
private
File url.
-
#width ⇒ Integer
readonly
private
File width.
Instance Method Summary collapse
-
#==(other) ⇒ TrueClass, FalseClass
private
Comparison method to comapre two File objects (and sub class objects).
-
#aspect_ratio ⇒ Float
private
A convenient function to return the aspect ratio of a given image.
-
#initialize(file) ⇒ Object
constructor
private
Initializer for an File.
-
#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(file) ⇒ 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 File
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/rubyhexagon/post/file.rb', line 65 def initialize(file) unless file.is_a?(Hash) raise ArgumentError, "#{file.class} is not a Hash" end unless file.keys.sort == %i[ext height md5 size url width] raise ArgumentError, 'Missing keys in file Hash.' end file.each do |k, v| if %i[width height ext size md5].include?(k) instance_variable_set("@#{k}".to_sym, v) elsif k == :url @url = v.nil? ? nil : 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.
File file extension
34 35 36 |
# File 'lib/rubyhexagon/post/file.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.
File height
42 43 44 |
# File 'lib/rubyhexagon/post/file.rb', line 42 def height @height end |
#md5 ⇒ 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.
File MD5 hash string
50 51 52 |
# File 'lib/rubyhexagon/post/file.rb', line 50 def md5 @md5 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.
File size
46 47 48 |
# File 'lib/rubyhexagon/post/file.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.
File url
30 31 32 |
# File 'lib/rubyhexagon/post/file.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.
File width
38 39 40 |
# File 'lib/rubyhexagon/post/file.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 File objects (and sub class objects)
106 107 108 109 |
# File 'lib/rubyhexagon/post/file.rb', line 106 def ==(other) other.is_a?(File) && @md5 == other.md5 && @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
95 96 97 |
# File 'lib/rubyhexagon/post/file.rb', line 95 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
86 87 88 |
# File 'lib/rubyhexagon/post/file.rb', line 86 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
118 119 120 121 122 123 124 |
# File 'lib/rubyhexagon/post/file.rb', line 118 def to_hash hash = {} instance_variables.each do |i| hash.store(i.to_s.sub(/^@/, '').to_sym, instance_variable_get(i)) end hash end |