Class: Rubyhexagon::Post::Sample Private
- Defined in:
- lib/rubyhexagon/post/sample.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 preview data. This is mostly an abstraction to have data structures in a more Ruby like nature.
Instance Attribute Summary
Attributes inherited from File
#ext, #height, #md5, #size, #url, #width
Instance Method Summary collapse
-
#exist? ⇒ TrueClass|FalseClass
private
Show if post has a sample or not.
-
#initialize(sample) ⇒ Object
constructor
private
Initializer for an Sample.
Methods inherited from File
#==, #aspect_ratio, #resolution, #to_hash
Constructor Details
#initialize(sample) ⇒ 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 Sample
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/rubyhexagon/post/sample.rb', line 39 def initialize(sample) unless sample.is_a?(Hash) raise ArgumentError, "#{sample.class} is not a Hash" end unless sample.keys.sort == %i[has height url width] raise ArgumentError, 'Missing keys in sample Hash.' end sample.each do |k, v| if %i[width height has].include?(k) instance_variable_set("@#{k}".to_sym, v) elsif k == :url @url = v.nil? ? nil : URI.parse(v) end end end |
Instance Method Details
#exist? ⇒ 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.
Show if post has a sample or not.
60 61 62 |
# File 'lib/rubyhexagon/post/sample.rb', line 60 def exist? @has end |