class PostRunner::PersonalRecords::SportRecords

Public Class Methods

new(p, sport) click to toggle source
Calls superclass method
# File lib/postrunner/PersonalRecords.rb, line 255
def initialize(p, sport)
  super(p)

  self.sport = sport
  self.all_time = @store.new(RecordSet, sport, nil)
  self.yearly = @store.new(PEROBS::Hash)
end

Public Instance Methods

delete_activity(activity) click to toggle source
# File lib/postrunner/PersonalRecords.rb, line 275
def delete_activity(activity)
  record_deleted = false
  ([ @all_time ] + @yearly.values).each do |r|
    record_deleted = true if r.delete_activity(activity)
  end

  record_deleted
end
each(&block) click to toggle source

Iterator for all Record objects that are stored in this data structure.

# File lib/postrunner/PersonalRecords.rb, line 293
def each(&block)
  records = @yearly.values
  records << @all_time if @all_time
  records.each { |r| r.each(&block) }
end
empty?() click to toggle source

Return true if no record is stored in this SportRecords object.

# File lib/postrunner/PersonalRecords.rb, line 285
def empty?
  return false unless @all_time.empty?
  @yearly.each_value { |r| return false unless r.empty? }

  true
end
register_result(result) click to toggle source
# File lib/postrunner/PersonalRecords.rb, line 263
def register_result(result)
  year = result.start_time.year.to_s
  unless @yearly[year]
    @yearly[year] = @store.new(RecordSet, @sport, year)
  end

  new_at = @all_time.register_result(result)
  new_yr = @yearly[year].register_result(result)

  new_at || new_yr
end
to_html(doc) click to toggle source
# File lib/postrunner/PersonalRecords.rb, line 312
def to_html(doc)
  return nil if empty?

  doc.div {
    doc.h3('All-time records')
    @all_time.to_html(doc)
    @yearly.values.sort do |r1, r2|
      r2.year.to_i <=> r1.year.to_i
    end.each do |record|
      unless record.empty?
        doc.h3("Records of #{record.year}")
        record.to_html(doc)
      end
    end
  }
end
to_s() click to toggle source
# File lib/postrunner/PersonalRecords.rb, line 299
def to_s
  return '' if empty?

  str = "All-time records:\n\n#{@all_time.to_s}" unless @all_time.empty?
  @yearly.values.sort{ |r1, r2| r2.year <=> r1.year }.each do |record|
    unless record.empty?
      str += "Records of #{record.year}:\n\n#{record.to_s}"
    end
  end

  str
end