class SportDb::Model::MatchCursorState

Attributes

index[R]

Public Class Methods

new() click to toggle source
# File lib/sportdb/models/utils.rb, line 24
def initialize
  @last_date     = DateTime.new( 1971, 1, 1 )
  @new_date      = true
  @new_year      = true
  @new_week      = true
  @index         = -1   # zero-based index; thus start off with -1 (e.g. -1+=1 => 0)
end

Public Instance Methods

new_date?() click to toggle source
# File lib/sportdb/models/utils.rb, line 34
def new_date?()  @new_date; end
new_week?() click to toggle source
# File lib/sportdb/models/utils.rb, line 36
def new_week?()  @new_week; end
new_year?() click to toggle source
# File lib/sportdb/models/utils.rb, line 35
def new_year?()  @new_year; end
next( match ) click to toggle source

add new league ? add new round ? add new time ?

# File lib/sportdb/models/utils.rb, line 43
def next( match )
  @index += 1   # zero-based index; start off with -1 (undefined/uninitialized)
  match_date = match.date  # cache date value ref

  if @last_date.year   == match_date.year  &&
     @last_date.month  == match_date.month &&
     @last_date.day    == match_date.day
    @new_date = false
  else
    @new_date = true

    # check for new_year
    if @last_date.year == match_date.year
      @new_year = false
    else
      @new_year = true
    end

    # check for new_week
    # -- todo: find a method for week number; do NOT use strftime; there must be something easier
    # -- check if activesupport adds  .week or similar ??? use it if it exists
    if @last_date.strftime('%V') == match_date.strftime('%V')
      @new_week = false
    else
      @new_week = true
    end
  end

  @last_date = match.date
end