Sha256: 7909663a0e33dd05bb67caa1b4e4eb88cf8e2d62f54995bc01ea9cad24b6f015

Contents?: true

Size: 1.35 KB

Versions: 23

Compression:

Stored size: 1.35 KB

Contents

module Scrivito

  class ObjDataFromService < ObjData
    def initialize(data)
      @data = data
    end

    def raw_value_and_type_of(attribute_name)
      return [value_of_widget_pool, nil] if attribute_name == '_widget_pool'
      if value_and_type = @data[attribute_name]
        value, type = value_and_type
        value = convert_value(value, type)
        [value, type]
      else
        [nil, nil]
      end
    end

    def convert_value(value, type)
      case type
      when 'html' then convert_text_links(value)
      else value
      end
    end

    def attribute_names
      @data.keys
    end

    def to_h
      @data.to_h
    end

    private

    def convert_text_links(value)
      text_links_conversion.convert(value)
    end

    def text_links_conversion
      @text_links_conversion = TextLinkConversion.new(text_links_map)
    end

    def text_links_map
      text_links = @data["_text_links"]
      return nil unless text_links

      text_links.first.each_with_object({}) do |link, map|
        map[link["link_id"]] = TextLink.new(link)
      end
    end

    def value_of_widget_pool
      if widget_pool = @data['_widget_pool']
        widget_pool.first.dup.tap do |hash|
          hash.each_pair do |widget_id, raw_widget_data|
            hash[widget_id] = self.class.new(raw_widget_data)
          end
        end
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
scrivito_sdk-1.0.0 lib/scrivito/obj_data_from_service.rb
scrivito_sdk-1.0.0.rc4 lib/scrivito/obj_data_from_service.rb
scrivito_sdk-1.0.0.rc3 lib/scrivito/obj_data_from_service.rb
scrivito_sdk-1.0.0.rc2 lib/scrivito/obj_data_from_service.rb
scrivito_sdk-1.0.0.rc1 lib/scrivito/obj_data_from_service.rb
scrivito_sdk-0.90.0 lib/scrivito/obj_data_from_service.rb
scrivito_sdk-0.90.0.rc3 lib/scrivito/obj_data_from_service.rb
scrivito_sdk-0.90.0.rc2 lib/scrivito/obj_data_from_service.rb
scrivito_sdk-0.90.0.rc1 lib/scrivito/obj_data_from_service.rb
scrivito_sdk-0.70.2 lib/scrivito/obj_data_from_service.rb
scrivito_sdk-0.71.2 lib/scrivito/obj_data_from_service.rb
scrivito_sdk-0.71.1 lib/scrivito/obj_data_from_service.rb
scrivito_sdk-0.70.1 lib/scrivito/obj_data_from_service.rb
scrivito_sdk-0.71.0 lib/scrivito/obj_data_from_service.rb
scrivito_sdk-0.71.0.rc2 lib/scrivito/obj_data_from_service.rb
scrivito_sdk-0.71.0.rc1 lib/scrivito/obj_data_from_service.rb
scrivito_sdk-0.70.0 lib/scrivito/obj_data_from_service.rb
scrivito_sdk-0.70.0.rc3 lib/scrivito/obj_data_from_service.rb
scrivito_sdk-0.70.0.rc2 lib/scrivito/obj_data_from_service.rb
scrivito_sdk-0.70.0.rc1 lib/scrivito/obj_data_from_service.rb