Module: CsvRowModel::Model

Extended by:
ActiveSupport::Concern
Includes:
ActiveWarnings, Concerns::InheritedClassVar, Children, Columns, DynamicColumns, Validators::ValidateAttributes
Defined in:
lib/csv_row_model/model.rb,
lib/csv_row_model/model/columns.rb,
lib/csv_row_model/model/children.rb,
lib/csv_row_model/model/comparison.rb,
lib/csv_row_model/model/file_model.rb,
lib/csv_row_model/model/dynamic_columns.rb,
lib/csv_row_model/model/csv_string_model.rb

Overview

Base module for representing a RowModel---a model that represents row(s).

Defined Under Namespace

Modules: Children, Columns, Comparison, DynamicColumns, FileModel Classes: CsvStringModel

Constant Summary

Constants included from DynamicColumns

DynamicColumns::VALID_OPTIONS_KEYS

Constants included from Columns

Columns::VALID_OPTIONS_KEYS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DynamicColumns

#attributes, dynamic_column, dynamic_column_headers, dynamic_column_names, dynamic_column_options, dynamic_index, headers, is_dynamic_column?, singular_dynamic_attribute_method_name

Methods included from Children

#append_child, #child?, #children_public_send, #deep_public_send, has_many

Methods included from Columns

#array_to_block_hash, #attributes, #attributes_from_column_names, column, column_names, format_header, #headers, headers, index, is_column_name?, options, #to_json

Methods included from Validators::ValidateAttributes

validate_attributes

Methods included from Concerns::InheritedClassVar

class_cache, clear_class_cache, deep_clear_class_cache, hidden_variable_name, inherited_ancestors, inherited_class_hash, inherited_class_var, inherited_class_variable_name, inherited_custom_class

Methods included from Concerns::InvalidOptions

check_and_merge_options

Instance Attribute Details

#initialized_atDateTime (readonly)

Return when self has been intialized

Returns:

  • (DateTime)

    return when self has been intialized



26
27
28
# File 'lib/csv_row_model/model.rb', line 26

def initialized_at
  @initialized_at
end

#parentModel (readonly)

Return the parent, if this instance is a child

Returns:

  • (Model)

    return the parent, if this instance is a child



23
24
25
# File 'lib/csv_row_model/model.rb', line 23

def parent
  @parent
end

Class Method Details

.csv_string_model(&block) ⇒ Object (protected)

Called to add validations to the csv_string_model_class



61
62
63
# File 'lib/csv_row_model/model.rb', line 61

def csv_string_model(&block)
  csv_string_model_class.class_eval(&block)
end

.csv_string_model_classClass

Returns the Class with validations of the csv_string_model.

Returns:

  • (Class)

    the Class with validations of the csv_string_model



55
56
57
# File 'lib/csv_row_model/model.rb', line 55

def csv_string_model_class
  @csv_string_model_class ||= inherited_custom_class(:csv_string_model_class, CsvStringModel)
end

Instance Method Details

#abort?Boolean

Safe to override.

Returns:

  • (Boolean)

    returns true, if the entire csv file should stop reading



49
50
51
# File 'lib/csv_row_model/model.rb', line 49

def abort?
  false
end

#initialize(source = nil, options = {}) ⇒ Object

Parameters:

  • source (NilClass) (defaults to: nil)

    not used here, see Input

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :parent (String)

    if the instance is a child, pass the parent



34
35
36
37
# File 'lib/csv_row_model/model.rb', line 34

def initialize(source=nil, options={})
  @initialized_at = DateTime.now
  @parent = options[:parent]
end

#skip?Boolean

Safe to override.

Returns:

  • (Boolean)

    returns true, if this instance should be skipped



42
43
44
# File 'lib/csv_row_model/model.rb', line 42

def skip?
  !valid?
end