Class: Match

Inherits:
Object
  • Object
show all
Defined in:
lib/fbtxt-pp/models/match.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(doc, data) ⇒ Match

Returns a new instance of Match.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/fbtxt-pp/models/match.rb', line 17

def initialize( doc, data )
     ## expect a data as (json) hash for now
     @doc = doc
     @h   = data


     ## note - always lookup full team records (use match inline only as refs)
     @team1 = @doc.find_team!( @h['team1'] )
     @team2 = @doc.find_team!( @h['team2'] )


     @date_utc       = parse_date_utc(   @h['datetime_utc'] )
     @date_local     = parse_date_local( @h['datetime_local'] )

     assert( @date_utc.sec == 0 && @date_local.sec == 0,
                "sec 00 expected" )

    ## note:  returns Rational (e.g. 3/1 or 1/4 etc.) use to_f/to_i to convert
    ## diff_in_hours = ((localDateTime - dateTime) * 24).to_f
    ## diff_in_days  =  localDateTime.jd - dateTime.jd

     # note - offset is in rational fraction of a day (e.g. 1/12 for 2hours)
     ##  was diff_in_hours
     @utc_offset = (@date_local.offset * 24).to_i

     ## pp [@date_utc, @date_local, @utc_offset]

     ## note - always lookup full stadium record (use match inline only as ref)
     @stadium  =  @doc.find_stadium!( @h['stadium'] )


     @score   =   @h['score'] ? Score.build( @h['score'] ) :  nil


     @goals1 =   @h['goals1'] ? @h['goals1'].map { |h| Goal.build( h ) } : nil
     @goals2 =   @h['goals2'] ? @h['goals2'].map { |h| Goal.build( h ) } : nil
end

Instance Attribute Details

#date_localObject (readonly)

use Match.build( h ) - why? why not?



9
10
11
# File 'lib/fbtxt-pp/models/match.rb', line 9

def date_local
  @date_local
end

#date_utcObject (readonly)

use Match.build( h ) - why? why not?



9
10
11
# File 'lib/fbtxt-pp/models/match.rb', line 9

def date_utc
  @date_utc
end

#goals1Object (readonly)

use Match.build( h ) - why? why not?



9
10
11
# File 'lib/fbtxt-pp/models/match.rb', line 9

def goals1
  @goals1
end

#goals2Object (readonly)

use Match.build( h ) - why? why not?



9
10
11
# File 'lib/fbtxt-pp/models/match.rb', line 9

def goals2
  @goals2
end

#scoreObject (readonly)

use Match.build( h ) - why? why not?



9
10
11
# File 'lib/fbtxt-pp/models/match.rb', line 9

def score
  @score
end

#stadiumObject (readonly)

use Match.build( h ) - why? why not?



9
10
11
# File 'lib/fbtxt-pp/models/match.rb', line 9

def stadium
  @stadium
end

#team1Object (readonly)

use Match.build( h ) - why? why not?



9
10
11
# File 'lib/fbtxt-pp/models/match.rb', line 9

def team1
  @team1
end

#team2Object (readonly)

use Match.build( h ) - why? why not?



9
10
11
# File 'lib/fbtxt-pp/models/match.rb', line 9

def team2
  @team2
end

#utc_offsetObject (readonly) Also known as: diff_in_hours

use Match.build( h ) - why? why not?



9
10
11
# File 'lib/fbtxt-pp/models/match.rb', line 9

def utc_offset
  @utc_offset
end

Instance Method Details

#attendanceObject



73
# File 'lib/fbtxt-pp/models/match.rb', line 73

def attendance() @h['attendance']; end

#dataObject

use _data to mark as "private" and do NOT use - why? why not?



58
# File 'lib/fbtxt-pp/models/match.rb', line 58

def data() @h; end

#groupObject

optional



68
# File 'lib/fbtxt-pp/models/match.rb', line 68

def group()      @h['group']; end

#matchdayObject

optional



70
# File 'lib/fbtxt-pp/models/match.rb', line 70

def matchday()   @h['matchday']; end

#numObject

optional (match) number



69
# File 'lib/fbtxt-pp/models/match.rb', line 69

def num()        @h['number']; end

#stageObject



67
# File 'lib/fbtxt-pp/models/match.rb', line 67

def stage()      @h['stage']; end