Class: Rubyhexagon::Post::Preview Private

Inherits:
File
  • Object
show all
Defined in:
lib/rubyhexagon/post/preview.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.

Author:

  • Maxine Michalski

Since:

  • 3.0.0

Instance Attribute Summary

Attributes inherited from File

#ext, #height, #md5, #size, #url, #width

Instance Method Summary collapse

Methods inherited from File

#==, #aspect_ratio, #resolution, #to_hash

Constructor Details

#initialize(preview) ⇒ 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 Preview

Parameters:

  • image (Hash)

    preview information

Author:

  • Maxine Michalski

Since:

  • 3.0.0



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/rubyhexagon/post/preview.rb', line 38

def initialize(preview)
  unless preview.is_a?(Hash)
    raise ArgumentError, "#{preview.class} is not a Hash"
  end
  unless preview.keys.sort == %i[height url width]
    raise ArgumentError, 'Missing keys in preview Hash.'
  end
  preview.each do |k, v|
    if %i[width height].include?(k)
      instance_variable_set("@#{k}".to_sym, v)
    elsif k == :url
      @url = v.nil? ? nil : URI.parse(v)
    end
  end
end