Module: WAR

Defined in:
lib/war/wrapper_activerecord.rb

Overview

Wrapper: ActiveRecord Methods return dictionaries which can be passed to ActiveRecord CRUD methods

Instance Method Summary collapse

Instance Method Details

#from_array(field_names = [], source = []) ⇒ Object

Create dictionary from array

Parameters:

  • field_names (Array) (defaults to: [])

    Symbols of fields

  • source (Array) (defaults to: [])

    Source data



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/war/wrapper_activerecord.rb', line 8

def from_array(field_names=[], source=[])
  fl = {}                # Resulting Field List
  idx = 0                # Source cursor

  # Create k:v  (from source) for each key (from field names)
  field_names.each do |f|
    fl[f] = source[idx]
    idx += 1
  end
  return fl
end

#from_array2d(field_names = [], source = []) ⇒ Object

Create dictionary from 2d array

Parameters:

  • field_names (Array) (defaults to: [])

    Symbols of fields

  • source ([Array]) (defaults to: [])

    Source data



24
25
26
27
28
29
30
31
# File 'lib/war/wrapper_activerecord.rb', line 24

def from_array2d (field_names=[], source=[])
  fl_a = []
  # Process each row of Source table
  source.each do |s|
    fl_a << from_array(field_names, s)
  end
  return fl_a
end