class Sqlite::Dataset

Attributes

header[R]
rows[R]

Public Class Methods

new(data) click to toggle source
# File lib/dataset.rb, line 5
def initialize(data)
  @header = @rows = []
  rows = split_lines data
  unless rows.empty?
    @header = split_pipe rows.shift
    @rows = rows.map { |item| split_pipe item }
  end
end

Public Instance Methods

compare(other) click to toggle source
# File lib/dataset.rb, line 14
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

Protected Instance Methods

same_amount(other_rows) click to toggle source
# File lib/dataset.rb, line 45
def same_amount(other_rows)
  @rows.length == other_rows.length
end
same_content(other_rows) click to toggle source
# File lib/dataset.rb, line 49
def same_content(other_rows)
  @rows.zip(other_rows).all? { |tuple| tuple[0] == tuple[1] }
end
same_header(other_header) click to toggle source
# File lib/dataset.rb, line 37
def same_header(other_header)
  @header.eql? other_header
end
same_rows(other_rows) click to toggle source
# File lib/dataset.rb, line 41
def same_rows(other_rows)
  same_amount(other_rows) && same_content(other_rows)
end
split_lines(str) click to toggle source
# File lib/dataset.rb, line 29
def split_lines(str)
  str.split(/\n+/i)
end
split_pipe(line) click to toggle source
# File lib/dataset.rb, line 33
def split_pipe(line)
  line.split(/\|/)
end