Class: Sublayer::Components::OutputAdapters::ListOfNamedStrings

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ ListOfNamedStrings

Returns a new instance of ListOfNamedStrings.



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

def initialize(options)
  @name = options[:name]
  @item_name = options[:item_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/list_of_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/list_of_named_strings.rb', line 5

def description
  @description
end

#item_nameObject (readonly)

Returns the value of attribute item_name.



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

def item_name
  @item_name
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

Instance Method Details

#materialize_result(raw_results) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/sublayer/components/output_adapters/list_of_named_strings.rb', line 38

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

#propertiesObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/sublayer/components/output_adapters/list_of_named_strings.rb', line 14

def properties
  [
    OpenStruct.new(
      name: @name,
      type: "array",
      description: @description,
      required: true,
      items: OpenStruct.new(
        type: "object",
        description: "a single #{@item_name}",
        name: @item_name,
        properties: @attributes.map do |attribute|
          OpenStruct.new(
            type: "string",
            name: attribute[:name],
            description: attribute[:description],
            required: true
          )
        end
      )
    )
  ]
end