Class: Fiona7::AttributeReaders::Helpers::LinkDeserializer

Inherits:
Object
  • Object
show all
Defined in:
lib/fiona7/attribute_readers/helpers/link_deserializer.rb

Instance Method Summary collapse

Instance Method Details

#call(link) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/fiona7/attribute_readers/helpers/link_deserializer.rb', line 5

def call(link)
  if link
    deserialized = {
      # remove possible external prefix for protcol-less urls
      url: link["url"].try(:gsub, /\Aexternal:/, ''),
      title: link["title"],
      target: link["target"],
      # content service uses destination
      destination: link["destination"].to_s,
      # rest api uses obj_id
      obj_id: link["destination"].to_s,
      query: link["search"],
      fragment: link["fragment"]
    }

    # TODO: refactor this code
    if deserialized[:url].present?
      deserialized.delete(:destination)
      deserialized.delete(:obj_id)
    end

    deserialized
  end
end