Class: KDomain::DomainModel::Load

Inherits:
Object
  • Object
show all
Includes:
KLog::Logging
Defined in:
lib/k_domain/domain_model/load.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source_file) ⇒ Load

Returns a new instance of Load.



17
18
19
# File 'lib/k_domain/domain_model/load.rb', line 17

def initialize(source_file)
  @source_file = source_file
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



15
16
17
# File 'lib/k_domain/domain_model/load.rb', line 15

def data
  @data
end

#source_fileObject (readonly)

Returns the value of attribute source_file.



14
15
16
# File 'lib/k_domain/domain_model/load.rb', line 14

def source_file
  @source_file
end

Instance Method Details

#callObject



21
22
23
24
25
26
27
28
29
30
# File 'lib/k_domain/domain_model/load.rb', line 21

def call
  json = File.read(source_file)
  @raw_data = KUtil.data.json_parse(json, as: :hash_symbolized)

  # This line is slow on big datasets
  @data = KDomain::Schemas::MainDataset.new(@raw_data)

  # This line is also slow on big datasets
  enrichment
end

#to_hObject



32
33
34
35
36
# File 'lib/k_domain/domain_model/load.rb', line 32

def to_h
  return nil unless defined? @raw_data

  @raw_data
end