Class: Sqlite::Dataset

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Dataset

Returns a new instance of Dataset.



5
6
7
8
9
# File 'lib/dataset.rb', line 5

def initialize(data)
  rows = data.split(/\n+/i)
  @header = rows.shift.split(/\|/)
  @rows   = rows.map { |row| row.split(/\|/) }
end

Instance Attribute Details

#headerObject (readonly)

Returns the value of attribute header.



3
4
5
# File 'lib/dataset.rb', line 3

def header
  @header
end

#rowsObject (readonly)

Returns the value of attribute rows.



3
4
5
# File 'lib/dataset.rb', line 3

def rows
  @rows
end

Instance Method Details

#compare(other) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/dataset.rb', line 11

def compare(other)
  same_header = same_header other.header
  same_rows   = same_rows other.rows

  if same_header & same_rows
    :equals
  elsif !same_header
    :distinct_columns
  else
    :distinct_rows
  end
end