Class: JsonDataExtractor::ExtractionInstruction

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

Overview

Represents a single field extraction instruction

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key:, element:, compiled_path:) ⇒ ExtractionInstruction

Returns a new instance of ExtractionInstruction.



8
9
10
11
12
# File 'lib/json_data_extractor/extraction_instruction.rb', line 8

def initialize(key:, element:, compiled_path:)
  @key = key
  @element = element
  @compiled_path = compiled_path
end

Instance Attribute Details

#compiled_pathObject (readonly)

Returns the value of attribute compiled_path.



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

def compiled_path
  @compiled_path
end

#elementObject (readonly)

Returns the value of attribute element.



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

def element
  @element
end

#keyObject (readonly)

Returns the value of attribute key.



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

def key
  @key
end

Instance Method Details

#extract(data) ⇒ Object



14
15
16
17
18
# File 'lib/json_data_extractor/extraction_instruction.rb', line 14

def extract(data)
  return element.fetch_default_value if compiled_path.nil?

  compiled_path.on(data)
end