Class: FlatKit::Jsonl::Record
- Defined in:
- lib/flat_kit/jsonl/record.rb
Overview
Internal: Class that exposes data from a JSONL format record to the flatkit api
Instance Attribute Summary collapse
-
#compare_data ⇒ Object
readonly
Returns the value of attribute compare_data.
Attributes inherited from Record
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
- #complete_structured_data ⇒ Object (also: #to_hash)
- #complete_structured_data? ⇒ Boolean
-
#data ⇒ Object
(also: #to_s)
overriding parent accessor since we may be initialized without raw bytes to parse.
-
#initialize(data:, compare_fields: :none, compare_data: {}, complete_structured_data: nil) ⇒ Record
constructor
A new instance of Record.
Methods inherited from Record
Constructor Details
#initialize(data:, compare_fields: :none, compare_data: {}, complete_structured_data: nil) ⇒ Record
Returns a new instance of Record.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/flat_kit/jsonl/record.rb', line 31 def initialize(data:, compare_fields: :none, compare_data: {}, complete_structured_data: nil) super(data: data, compare_fields: compare_fields) @complete_structured_data = complete_structured_data @compare_data = if complete_structured_data? && (compare_data.nil? || compare_data.empty?) complete_structured_data else compare_data end # only load compare data if it dosn't exist quick_parse if data && compare_data.empty? end |
Instance Attribute Details
#compare_data ⇒ Object (readonly)
Returns the value of attribute compare_data.
11 12 13 |
# File 'lib/flat_kit/jsonl/record.rb', line 11 def compare_data @compare_data end |
Class Method Details
.format_name ⇒ Object
13 14 15 |
# File 'lib/flat_kit/jsonl/record.rb', line 13 def self.format_name ::FlatKit::Jsonl::Format.format_name end |
.from_record(record) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/flat_kit/jsonl/record.rb', line 17 def self.from_record(record) if record.instance_of?(FlatKit::Jsonl::Record) structured = record.complete_structured_data? ? record.complete_structured_data : nil new(data: record.data, compare_fields: record.compare_fields, compare_data: record.compare_data, complete_structured_data: structured) else new(data: nil, compare_fields: record.compare_fields, complete_structured_data: record.to_hash) end end |
Instance Method Details
#[](key) ⇒ Object
48 49 50 |
# File 'lib/flat_kit/jsonl/record.rb', line 48 def [](key) compare_data[key] end |
#complete_structured_data ⇒ Object Also known as: to_hash
52 53 54 |
# File 'lib/flat_kit/jsonl/record.rb', line 52 def complete_structured_data @complete_structured_data ||= Oj.load(data, mode: :strict) end |
#complete_structured_data? ⇒ Boolean
57 58 59 |
# File 'lib/flat_kit/jsonl/record.rb', line 57 def complete_structured_data? !(@complete_structured_data.nil? || @complete_structured_data.empty?) end |
#data ⇒ Object Also known as: to_s
overriding parent accessor since we may be initialized without raw bytes to parse
63 64 65 66 |
# File 'lib/flat_kit/jsonl/record.rb', line 63 def data @data = Oj.dump(complete_structured_data, mode: :json) if @data.nil? && complete_structured_data? @data end |