class Athena::Record

Attributes

block[R]
id[R]
struct[R]

Public Class Methods

[](field = nil, config = nil) click to toggle source
# File lib/athena/record.rb, line 46
def [](field = nil, config = nil)
  record = records.last
  raise NoRecordError unless record

  record.fill(field, config) if field && config
  record
end
new(id = nil, block = nil, add = !block) { |self| ... } click to toggle source
# File lib/athena/record.rb, line 58
def initialize(id = nil, block = nil, add = !block)
  @id, @block, @struct = id || object_id.map_positive, block, {}

  add_record if add

  if block_given?
    begin
      yield self
    ensure
      close
    end
  end
end
records() click to toggle source
# File lib/athena/record.rb, line 42
def records
  @records
end

Public Instance Methods

close() click to toggle source
# File lib/athena/record.rb, line 81
def close
  block ? block[self] : self
end
fill(field, config) click to toggle source
# File lib/athena/record.rb, line 72
def fill(field, config)
  struct[field] ||= config.merge(:values => Hash.new { |h, k| h[k] = [] })
end
to(format) click to toggle source
# File lib/athena/record.rb, line 85
def to(format)
  Formats[:out, format].convert(self)
end
update(element, data, field_config = nil) click to toggle source
# File lib/athena/record.rb, line 76
def update(element, data, field_config = nil)
  field_config.each { |field, config| fill(field, config) } if field_config
  struct.each_key { |field| struct[field][:values][element] << data }
end

Private Instance Methods

add_record() click to toggle source
# File lib/athena/record.rb, line 91
def add_record
  self.class.records << self
end