Class: Reporter::Record::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/reporter/record/base.rb

Overview

Internal: A base class for data record objects.

Examples

class MyRecord < Reporter::Record::Base
  # ...
end

Instance Method Summary collapse

Constructor Details

#initialize(data = Hash.new) ⇒ Base

Public: Initialize a new Record from a data hash.

data - A Hash mapping String field names to their values

(optional; defaults to an empty hash)

Examples

class Employee < Reporter::Record::Base
  # Public: Initialize a new employee with a particular name.
  #
  # name - A String representing the name of the employee.
  #
  # Examples
  #
  #   john = Employee.new("John")
  def initialize(name)
    super({"name": name})
  end
end


32
33
34
# File 'lib/reporter/record/base.rb', line 32

def initialize(data = Hash.new)
  @data = data
end

Instance Method Details

#==(other_record) ⇒ Object Also known as: eql?

Public: Determines if two records are equal.

Returns true if the records are equal, otherwise returns false.



46
47
48
49
# File 'lib/reporter/record/base.rb', line 46

def ==(other_record)
  other_record.class == self.class &&
    other_record.instance_exec { @data } == @data
end

#hashObject

Public: Retrieves the hash for this record.

Returns the hash.



39
40
41
# File 'lib/reporter/record/base.rb', line 39

def hash
  [@data, self.class].hash
end