class PEROBS::IDListPage

Attributes

record[RW]
uid[R]
values[R]

Public Class Methods

load(page_file, uid, ref) click to toggle source
# File lib/perobs/IDListPage.rb, line 43
def IDListPage::load(page_file, uid, ref)
  page_file.load(uid, ref)
end
new(page_file, record, uid, values = []) click to toggle source
# File lib/perobs/IDListPage.rb, line 35
def initialize(page_file, record, uid, values = [])
  @page_file = page_file
  @record = record
  @uid = uid
  @values = values
  @record.page_entries = @values.length
end

Public Instance Methods

check() click to toggle source
# File lib/perobs/IDListPage.rb, line 89
def check
  last_value = nil
  @values.each_with_index do |v, i|
    if last_value && last_value >= v
      raise RuntimeError, "The values #{last_value} and #{v} must be " +
        "strictly ascending: #{@values.inspect}"
    end
    last_value = v
  end
end
delete(max_id) click to toggle source
# File lib/perobs/IDListPage.rb, line 77
def delete(max_id)
  a = []
  @values.delete_if { |v| v > max_id ? a << v : false }

  unless a.empty?
    @record.page_entries = @values.length
    @page_file.mark_page_as_modified(self)
  end

  a
end
include?(id) click to toggle source
# File lib/perobs/IDListPage.rb, line 73
def include?(id)
  !(v = @values.bsearch { |v| v >= id }).nil? && v == id
end
insert(id) click to toggle source
# File lib/perobs/IDListPage.rb, line 59
def insert(id)
  if is_full?
    raise ArgumentError, "IDListPage is already full"
  end
  index = @values.bsearch_index { |v| v >= id } || @values.length

  # If the value isn't stored already, insert it.
  if @values[index] != id
    @values.insert(index, id)
    @record.page_entries = @values.length
    @page_file.mark_page_as_modified(self)
  end
end
is_full?() click to toggle source
# File lib/perobs/IDListPage.rb, line 47
def is_full?
  @values.length >= @page_file.page_size
end
length() click to toggle source
# File lib/perobs/IDListPage.rb, line 51
def length
  @values.length
end
save() click to toggle source
# File lib/perobs/IDListPage.rb, line 55
def save
  @page_file.save_page(self)
end
to_s() click to toggle source
# File lib/perobs/IDListPage.rb, line 100
def to_s
  "[ #{@values.join(', ')} ]"
end