Class: Sublayer::Components::OutputAdapters::NamedStrings

Inherits:
Object
  • Object
show all
Defined in:
lib/sublayer/components/output_adapters/named_strings.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ NamedStrings

Returns a new instance of NamedStrings.



7
8
9
10
11
# File 'lib/sublayer/components/output_adapters/named_strings.rb', line 7

def initialize(options)
  @name = options[:name]
  @description = options[:description]
  @attributes = options[:attributes]
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



5
6
7
# File 'lib/sublayer/components/output_adapters/named_strings.rb', line 5

def attributes
  @attributes
end

#descriptionObject (readonly)

Returns the value of attribute description.



5
6
7
# File 'lib/sublayer/components/output_adapters/named_strings.rb', line 5

def description
  @description
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/sublayer/components/output_adapters/named_strings.rb', line 5

def name
  @name
end

Instance Method Details

#materialize_result(raw_result) ⇒ Object



27
28
29
# File 'lib/sublayer/components/output_adapters/named_strings.rb', line 27

def materialize_result(raw_result)
  OpenStruct.new( @attributes.map { |attribute| [attribute[:name], raw_result[attribute[:name]]] }.to_h)
end

#propertiesObject



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/sublayer/components/output_adapters/named_strings.rb', line 13

def properties
  [
    OpenStruct.new(
      name: @name,
      type: "object",
      description: @description,
      required: true,
      properties: @attributes.map { |attribute|
        OpenStruct.new(type: "string", description: attribute[:description], required: true, name: attribute[:name]) 
      }
    )
  ]
end