Class: CSVModel::Model

Inherits:
Object
  • Object
show all
Includes:
Utilities::Options
Defined in:
lib/csv_model/model.rb

Instance Attribute Summary collapse

Attributes included from Utilities::Options

#options

Instance Method Summary collapse

Methods included from Utilities::Options

#option

Constructor Details

#initialize(data, options = {}) ⇒ Model

Returns a new instance of Model.



9
10
11
12
13
14
# File 'lib/csv_model/model.rb', line 9

def initialize(data, options = {})
  @data = data
  @rows = []
  @options = options
  @keys = Set.new
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



7
8
9
# File 'lib/csv_model/model.rb', line 7

def data
  @data
end

#headerObject (readonly)

Returns the value of attribute header.



7
8
9
# File 'lib/csv_model/model.rb', line 7

def header
  @header
end

#keysObject (readonly)

Returns the value of attribute keys.



7
8
9
# File 'lib/csv_model/model.rb', line 7

def keys
  @keys
end

#parse_errorObject (readonly)

Returns the value of attribute parse_error.



7
8
9
# File 'lib/csv_model/model.rb', line 7

def parse_error
  @parse_error
end

#rowsObject (readonly)

Returns the value of attribute rows.



7
8
9
# File 'lib/csv_model/model.rb', line 7

def rows
  @rows
end

Instance Method Details

#row_countObject



16
17
18
# File 'lib/csv_model/model.rb', line 16

def row_count
  rows.count
end

#structure_errorsObject



20
21
22
23
24
# File 'lib/csv_model/model.rb', line 20

def structure_errors
  return [parse_error] if parse_error
  return header.errors if !header.valid?
  []
end

#structure_valid?Boolean

Returns:

  • (Boolean)


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

def structure_valid?
  parse_error.nil? && header.valid?
end