Class: SportDb::Model::MatchCursorState

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMatchCursorState

Returns a new instance of MatchCursorState.



24
25
26
27
28
29
30
# 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

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(match) ⇒ 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( 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