Class: Remi::DataSubject

Inherits:
Object
  • Object
show all
Defined in:
lib/remi/data_subject.rb

Direct Known Subclasses

DataSource, DataTarget

Defined Under Namespace

Modules: CsvFile, Postgres, Salesforce

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, fields: Remi::Fields.new, remi_df_type: :daru, logger: Remi::Settings.logger, **kargs, &block) ⇒ DataSubject

Returns a new instance of DataSubject.



3
4
5
6
7
# File 'lib/remi/data_subject.rb', line 3

def initialize(*args, fields: Remi::Fields.new, remi_df_type: :daru, logger: Remi::Settings.logger, **kargs, &block)
  @fields = fields
  @remi_df_type = remi_df_type
  @logger = logger
end

Instance Attribute Details

#fieldsObject

Public: Fields defined for this data subject



10
11
12
# File 'lib/remi/data_subject.rb', line 10

def fields
  @fields
end

Instance Method Details

#dfObject

Public: Access the dataframe from a DataSource

Returns a Remi::DataFrame



20
21
22
# File 'lib/remi/data_subject.rb', line 20

def df
  @dataframe ||= Remi::DataFrame.create(@remi_df_type, [], order: @fields.keys)
end

#df=(new_dataframe) ⇒ Object

Public: Reassigns the dataframe associated with this subject

Returns the assigned dataframe



27
28
29
30
31
32
33
# File 'lib/remi/data_subject.rb', line 27

def df=(new_dataframe)
  if new_dataframe.respond_to? :remi_df_type
    @dataframe = new_dataframe
  else
    @dataframe = Remi::DataFrame.create(@remi_df_type, new_dataframe)
  end
end

#enforce_types(*types) ⇒ Object

Public: Enforces types defined in the field metadata. For example, if a field has metadata with type: :date, then the type enforcer will convert data in that field into a date, and will throw an error if it is unable to parse any of the values.

types - If set, restricts the data types that are enforced to just those listed.

Returns nothing.



43
44
45
46
47
48
49
50
51
# File 'lib/remi/data_subject.rb', line 43

def enforce_types(*types)
  sttm = SourceToTargetMap.new(df, source_metadata: fields)
  fields.keys.each do |field|
    next unless (types.size == 0 || types.include?(fields[field][:type])) && df.vectors.include?(field)
    sttm.source(field).target(field).transform(Remi::Transform::EnforceType.new).execute
  end

  nil
end

#field_symbolizerObject

Public: The default method for symbolizing field names



13
14
15
# File 'lib/remi/data_subject.rb', line 13

def field_symbolizer
  Remi::FieldSymbolizers[:standard]
end