Class: Match
- Inherits:
-
Object
- Object
- Match
- Defined in:
- lib/fbtxt-pp/models/match.rb
Instance Attribute Summary collapse
-
#date_local ⇒ Object
readonly
use Match.build( h ) - why? why not?.
-
#date_utc ⇒ Object
readonly
use Match.build( h ) - why? why not?.
-
#goals1 ⇒ Object
readonly
use Match.build( h ) - why? why not?.
-
#goals2 ⇒ Object
readonly
use Match.build( h ) - why? why not?.
-
#score ⇒ Object
readonly
use Match.build( h ) - why? why not?.
-
#stadium ⇒ Object
readonly
use Match.build( h ) - why? why not?.
-
#team1 ⇒ Object
readonly
use Match.build( h ) - why? why not?.
-
#team2 ⇒ Object
readonly
use Match.build( h ) - why? why not?.
-
#utc_offset ⇒ Object
(also: #diff_in_hours)
readonly
use Match.build( h ) - why? why not?.
Instance Method Summary collapse
- #attendance ⇒ Object
-
#data ⇒ Object
use _data to mark as "private" and do NOT use - why? why not?.
-
#group ⇒ Object
optional.
-
#initialize(doc, data) ⇒ Match
constructor
A new instance of Match.
-
#matchday ⇒ Object
optional.
-
#num ⇒ Object
optional (match) number.
- #stage ⇒ Object
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_local ⇒ Object (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_utc ⇒ Object (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 |
#goals1 ⇒ Object (readonly)
use Match.build( h ) - why? why not?
9 10 11 |
# File 'lib/fbtxt-pp/models/match.rb', line 9 def goals1 @goals1 end |
#goals2 ⇒ Object (readonly)
use Match.build( h ) - why? why not?
9 10 11 |
# File 'lib/fbtxt-pp/models/match.rb', line 9 def goals2 @goals2 end |
#score ⇒ Object (readonly)
use Match.build( h ) - why? why not?
9 10 11 |
# File 'lib/fbtxt-pp/models/match.rb', line 9 def score @score end |
#stadium ⇒ Object (readonly)
use Match.build( h ) - why? why not?
9 10 11 |
# File 'lib/fbtxt-pp/models/match.rb', line 9 def stadium @stadium end |
#team1 ⇒ Object (readonly)
use Match.build( h ) - why? why not?
9 10 11 |
# File 'lib/fbtxt-pp/models/match.rb', line 9 def team1 @team1 end |
#team2 ⇒ Object (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_offset ⇒ Object (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
#attendance ⇒ Object
73 |
# File 'lib/fbtxt-pp/models/match.rb', line 73 def attendance() @h['attendance']; end |
#data ⇒ Object
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 |
#group ⇒ Object
optional
68 |
# File 'lib/fbtxt-pp/models/match.rb', line 68 def group() @h['group']; end |
#matchday ⇒ Object
optional
70 |
# File 'lib/fbtxt-pp/models/match.rb', line 70 def matchday() @h['matchday']; end |
#num ⇒ Object
optional (match) number
69 |
# File 'lib/fbtxt-pp/models/match.rb', line 69 def num() @h['number']; end |
#stage ⇒ Object
67 |
# File 'lib/fbtxt-pp/models/match.rb', line 67 def stage() @h['stage']; end |