Class: SportDb::Model::GameCursorState

Inherits:
Object
  • Object
show all
Defined in:
lib/sportdb/models/utils.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGameCursorState

Returns a new instance of GameCursorState.



24
25
26
27
28
29
30
# File 'lib/sportdb/models/utils.rb', line 24

def initialize
  @last_play_at  = 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

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



32
33
34
# File 'lib/sportdb/models/utils.rb', line 32

def index
  @index
end

Instance Method Details

#new_date?Boolean

Returns:

  • (Boolean)


34
# File 'lib/sportdb/models/utils.rb', line 34

def new_date?()  @new_date; end

#new_week?Boolean

Returns:

  • (Boolean)


36
# File 'lib/sportdb/models/utils.rb', line 36

def new_week?()  @new_week; end

#new_year?Boolean

Returns:

  • (Boolean)


35
# File 'lib/sportdb/models/utils.rb', line 35

def new_year?()  @new_year; end

#next(game) ⇒ Object

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



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/sportdb/models/utils.rb', line 43

def next( game )
  @index += 1   # zero-based index; start off with -1 (undefined/uninitialized)
  game_play_at = game.play_at  # cache play_at value ref

  if @last_play_at.year   == game_play_at.year  &&
     @last_play_at.month  == game_play_at.month &&
     @last_play_at.day    == game_play_at.day
    @new_date = false
  else
    @new_date = true
      
    # check for new_year
    if @last_play_at.year == game_play_at.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_play_at.strftime('%V') == game_play_at.strftime('%V')
      @new_week = false
    else
      @new_week = true
    end
  end

  @last_play_at = game.play_at
end