Class: FlatKit::Jsonl::Record
- Defined in:
- lib/flat_kit/jsonl/record.rb
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: Hash.new, complete_structured_data: nil) ⇒ Record
constructor
A new instance of Record.
Methods inherited from Record
Constructor Details
#initialize(data:, compare_fields: :none, compare_data: Hash.new, complete_structured_data: nil) ⇒ Record
Returns a new instance of Record.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/flat_kit/jsonl/record.rb', line 27 def initialize(data:, compare_fields: :none, compare_data: Hash.new, complete_structured_data: nil) super(data: data, compare_fields: compare_fields) @complete_structured_data = complete_structured_data if complete_structured_data? && (compare_data.nil? || compare_data.empty?) then @compare_data = complete_structured_data else @compare_data = compare_data end # only load compare data if it dosn't exist if data && compare_data.empty? then quick_parse end end |
Instance Attribute Details
#compare_data ⇒ Object (readonly)
Returns the value of attribute compare_data.
7 8 9 |
# File 'lib/flat_kit/jsonl/record.rb', line 7 def compare_data @compare_data end |
Class Method Details
.format_name ⇒ Object
9 10 11 |
# File 'lib/flat_kit/jsonl/record.rb', line 9 def self.format_name ::FlatKit::Jsonl::Format.format_name end |
.from_record(record) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/flat_kit/jsonl/record.rb', line 13 def self.from_record(record) if record.instance_of?(FlatKit::Jsonl::Record) then 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
46 47 48 |
# File 'lib/flat_kit/jsonl/record.rb', line 46 def [](key) compare_data[key] end |
#complete_structured_data ⇒ Object Also known as: to_hash
50 51 52 |
# File 'lib/flat_kit/jsonl/record.rb', line 50 def complete_structured_data @complete_structured_data ||= Oj.load(data, mode: :strict) end |
#complete_structured_data? ⇒ Boolean
55 56 57 |
# File 'lib/flat_kit/jsonl/record.rb', line 55 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
61 62 63 64 65 66 |
# File 'lib/flat_kit/jsonl/record.rb', line 61 def data if @data.nil? && complete_structured_data? then @data = Oj.dump(complete_structured_data, mode: :json) end @data end |