Class: JsonDataExtractor::SchemaElement

Inherits:
Object
  • Object
show all
Defined in:
lib/json_data_extractor/schema_element.rb

Overview

parses the input schema element

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema_definition) ⇒ SchemaElement

Returns a new instance of SchemaElement.



8
9
10
11
12
13
14
15
16
17
# File 'lib/json_data_extractor/schema_element.rb', line 8

def initialize(schema_definition)
  validate_schema_definition(schema_definition)

  @path = schema_definition[:path] if schema_definition.key?(:path)
  @default_value = schema_definition[:default]
  @maps = fetch_maps(schema_definition[:maps] || schema_definition[:map])
  @modifiers = fetch_modifiers(schema_definition[:modifiers] || schema_definition[:modifier])
  @array_type = schema_definition[:type] == 'array'
  @nested = schema_definition[:schema]
end

Instance Attribute Details

#array_typeObject (readonly)

Returns the value of attribute array_type.



6
7
8
# File 'lib/json_data_extractor/schema_element.rb', line 6

def array_type
  @array_type
end

#default_valueObject (readonly)

Returns the value of attribute default_value.



6
7
8
# File 'lib/json_data_extractor/schema_element.rb', line 6

def default_value
  @default_value
end

#mapsObject (readonly)

Returns the value of attribute maps.



6
7
8
# File 'lib/json_data_extractor/schema_element.rb', line 6

def maps
  @maps
end

#modifiersObject (readonly)

Returns the value of attribute modifiers.



6
7
8
# File 'lib/json_data_extractor/schema_element.rb', line 6

def modifiers
  @modifiers
end

#nestedObject (readonly)

Returns the value of attribute nested.



6
7
8
# File 'lib/json_data_extractor/schema_element.rb', line 6

def nested
  @nested
end

#pathObject (readonly)

Returns the value of attribute path.



6
7
8
# File 'lib/json_data_extractor/schema_element.rb', line 6

def path
  @path
end

Instance Method Details

#fetch_default_valueObject



19
20
21
# File 'lib/json_data_extractor/schema_element.rb', line 19

def fetch_default_value
  @default_value.respond_to?(:call) ? @default_value.call : @default_value
end