Class: Row

Inherits:
Object
  • Object
show all
Defined in:
lib/dbexpect/row.rb

Overview

Copyright 2012 C3 Business Solutions

This file is part of dbexpect.

dbexpect is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

dbexpect is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with dbexpect.  If not, see <http://www.gnu.org/licenses/>.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(row, column_order) ⇒ Row

Returns a new instance of Row.



19
20
21
22
# File 'lib/dbexpect/row.rb', line 19

def initialize(row,column_order)
  @row = row
  @column_order = column_order
end

Instance Attribute Details

#rowObject

Returns the value of attribute row.



18
19
20
# File 'lib/dbexpect/row.rb', line 18

def row
  @row
end

Instance Method Details

#columnsObject



39
40
41
# File 'lib/dbexpect/row.rb', line 39

def columns
  @column_order.join(',')
end

#insert_stmt(schema, name) ⇒ Object



24
25
26
27
28
29
# File 'lib/dbexpect/row.rb', line 24

def insert_stmt(schema,name)
    stmt = <<SQL
INSERT INTO #{schema}.#{name} (#{columns})
VALUES #{row_values}
SQL
end

#row_valuesObject



31
32
33
# File 'lib/dbexpect/row.rb', line 31

def row_values
  '(' + @column_order.map {|col| row[col].db_str }.join(',') + ')'
end

#where_clauseObject



35
36
37
# File 'lib/dbexpect/row.rb', line 35

def where_clause
  @column_order.map {|col| "#{col} #{row[col].equality_test}" }.join(' AND ')
end