class Taxonifi::Model::Base

A base class for all Taxonifi::Models that represent “individuals” (as opposed to collections of indviduals).

Attributes

external_id[RW]

Optionally store an id representing the original id usef for this record.

id[RW]

The id of this object.

row_number[RW]

Optionly store the row this came from

Public Instance Methods

ancestor_ids() click to toggle source

The ids only of ancestors. Immediate ancestor id is in [].last

# File lib/models/base.rb, line 31
def ancestor_ids
  i = 0 # check for recursion
  ids = []
  p = parent 
  while !p.nil?
    ids.unshift p.id
    p = p.parent
    i += 1
    raise Taxonifi::ModelError, "Infite recursion in parent string detected for Base model object #{id}." if i > 100
  end
  ids
end
ancestors() click to toggle source

Ancestor objects for subclasses that have a parent property. TODO: check for parent attributes

# File lib/models/base.rb, line 47
def ancestors
  i = 0 # check for recursion
  ancestors = []
  p = parent 
  while !p.nil?
    ancestors.unshift p
    p = p.parent
    i += 1
    raise Taxonifi::ModelError, "Infite recursion in parent string detected for Base model object #{id.display_name}." if i > 100
  end
  ancestors 
end
build(attributes, opts) click to toggle source

Assign on new() all attributes for the ATTRIBUTES constant in a given subclass. !! Check validity prior to building.

# File lib/models/base.rb, line 18
def build(attributes, opts)
  attributes.each do |c|
    self.send("#{c}=",opts[c]) if !opts[c].nil?
  end
end
id=(id) click to toggle source
# File lib/models/base.rb, line 24
def id=(id)
  raise Taxonifi::ModelError, "Base model objects must have Fixnum ids." if !id.nil? && id.class != Fixnum
  @id = id
end
identical?(obj) click to toggle source

Determines identity base ONLY on attributes in ATTRIBUTES.

# File lib/models/base.rb, line 62
def identical?(obj)
  raise Taxonifi::ModelError, "Objects are not comparible." if obj.class != self.class
  self.class::ATTRIBUTES.each do |a|
    next if a == :id # don't compare
    return false if obj.send(a) != self.send(a)
  end
  return true
end