Module: Poms::Fields::Media

Extended by:
Media
Included in:
Poms::Fields, Media
Defined in:
lib/poms/fields/media.rb

Overview

Module to retrieve media related information from poms items.

Constant Summary collapse

IMAGE_TYPE_PRIORITY =
%w[PROMO_LANDSCAPE PICTURE].freeze

Instance Method Summary collapse

Instance Method Details

#first_image_id(item) ⇒ Object

Returns the id of the first image or nil if there are none.



28
29
30
31
# File 'lib/poms/fields/media.rb', line 28

def first_image_id(item)
  return unless images(item)
  image_id(images(item).first)
end

#image_id(image) ⇒ Object

Extracts the image id from an image hash Expects a hash of just an image from POMS



18
19
20
21
# File 'lib/poms/fields/media.rb', line 18

def image_id(image)
  return unless image['imageUri']
  image['imageUri'].split(':').last
end

#image_order_index(image) ⇒ Object



23
24
25
# File 'lib/poms/fields/media.rb', line 23

def image_order_index(image)
  IMAGE_TYPE_PRIORITY.index(image['type']) || IMAGE_TYPE_PRIORITY.size
end

#images(item) ⇒ Object

Returns the images from the hash



10
11
12
13
14
# File 'lib/poms/fields/media.rb', line 10

def images(item)
  item['images'].try(:sort_by) do |i|
    image_order_index(i)
  end
end