Class: Remi::DataSubject
- Inherits:
-
Object
- Object
- Remi::DataSubject
- Defined in:
- lib/remi/data_subject.rb
Direct Known Subclasses
Defined Under Namespace
Modules: CsvFile, Postgres, Salesforce
Instance Attribute Summary collapse
-
#fields ⇒ Object
Public: Fields defined for this data subject.
Instance Method Summary collapse
-
#df ⇒ Object
Public: Access the dataframe from a DataSource.
-
#df=(new_dataframe) ⇒ Object
Public: Reassigns the dataframe associated with this subject.
-
#enforce_types(*types) ⇒ Object
Public: Enforces types defined in the field metadata.
-
#field_symbolizer ⇒ Object
Public: The default method for symbolizing field names.
-
#initialize(*args, fields: Remi::Fields.new, remi_df_type: :daru, logger: Remi::Settings.logger, **kargs, &block) ⇒ DataSubject
constructor
A new instance of DataSubject.
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
#fields ⇒ Object
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
#df ⇒ Object
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_symbolizer ⇒ Object
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 |