class Caracal::Core::Models::ImageModel

This class handles block options passed to the img method.

Attributes

image_align[R]
image_bottom[R]
image_data[R]
image_height[R]
image_left[R]
image_ppi[R]
image_right[R]
image_top[R]
image_url[R]

accessors

image_width[R]

Public Class Methods

new(options={}, &block) click to toggle source

initialization

Calls superclass method Caracal::Core::Models::BaseModel::new
# File lib/caracal/core/models/image_model.rb, line 40
def initialize(options={}, &block)
  @image_ppi    = DEFAULT_IMAGE_PPI
  @image_width  = DEFAULT_IMAGE_WIDTH
  @image_height = DEFAULT_IMAGE_HEIGHT
  @image_align  = DEFAULT_IMAGE_ALIGN
  @image_top    = DEFAULT_IMAGE_TOP
  @image_bottom = DEFAULT_IMAGE_BOTTOM
  @image_left   = DEFAULT_IMAGE_LEFT
  @image_right  = DEFAULT_IMAGE_RIGHT
  
  super options, &block
end

Public Instance Methods

relationship_target() click to toggle source
# File lib/caracal/core/models/image_model.rb, line 74
def relationship_target
  image_data || image_url
end
valid?() click to toggle source
VALIDATION ==============================
# File lib/caracal/core/models/image_model.rb, line 104
def valid?
  dims = [:ppi, :width, :height, :top, :bottom, :left, :right].map { |m| send("image_#{ m }") }
  dims.all? { |d| d > 0 }
end

Private Instance Methods

option_keys() click to toggle source
# File lib/caracal/core/models/image_model.rb, line 116
def option_keys
  [:url, :width, :height, :align, :top, :bottom, :left, :right, :data]
end
pixels_to_emus(value, ppi) click to toggle source
# File lib/caracal/core/models/image_model.rb, line 120
def pixels_to_emus(value, ppi)
  pixels        = value.to_i
  inches        = pixels / ppi.to_f
  emus_per_inch = 914400

  emus = (inches * emus_per_inch).to_i 
end