Class: Spotlight::PageContent::SirTrevor

Inherits:
Object
  • Object
show all
Defined in:
app/models/spotlight/page_content/sir_trevor.rb

Overview

Sir-Trevor created content

Class Method Summary collapse

Class Method Details

.parse(page, attribute) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/models/spotlight/page_content/sir_trevor.rb', line 7

def self.parse(page, attribute)
  blocks = page.read_attribute(attribute)
  blocks ||= [].to_json

  return [] if blocks.blank?

  blocks = JSON.parse(blocks, symbolize_names: true) if blocks.is_a?(String)

  if blocks.is_a?(Hash)
    blocks = blocks[:data] || blocks['data'] or
      raise IndexError, 'No block data found'
  end

  blocks.map do |obj|
    SirTrevorRails::Block.from_hash(obj, page)
  end
end