Class: Goal
Instance Attribute Summary collapse
-
#minute ⇒ Object
readonly
Returns the value of attribute minute.
-
#og ⇒ Object
readonly
Returns the value of attribute og.
-
#pen ⇒ Object
readonly
Returns the value of attribute pen.
-
#player ⇒ Object
readonly
Returns the value of attribute player.
Class Method Summary collapse
-
._build_ary(recs, players:, penalties: false) ⇒ Object
add alias _build_all or _build_collection or ?? - why? why not?.
- .build(h, players:) ⇒ Object
Instance Method Summary collapse
- #as_json ⇒ Object
-
#initialize(player:, minute:, pen: false, og: false) ⇒ Goal
constructor
A new instance of Goal.
Constructor Details
#initialize(player:, minute:, pen: false, og: false) ⇒ Goal
Returns a new instance of Goal.
97 98 99 100 101 102 103 104 105 |
# File 'lib/fifadat/models/goal.rb', line 97 def initialize( player:, minute:, pen: false, og: false) @player = player @minute = minute @pen = pen @og = og end |
Instance Attribute Details
#minute ⇒ Object (readonly)
Returns the value of attribute minute.
94 95 96 |
# File 'lib/fifadat/models/goal.rb', line 94 def minute @minute end |
#og ⇒ Object (readonly)
Returns the value of attribute og.
94 95 96 |
# File 'lib/fifadat/models/goal.rb', line 94 def og @og end |
#pen ⇒ Object (readonly)
Returns the value of attribute pen.
94 95 96 |
# File 'lib/fifadat/models/goal.rb', line 94 def pen @pen end |
#player ⇒ Object (readonly)
Returns the value of attribute player.
94 95 96 |
# File 'lib/fifadat/models/goal.rb', line 94 def player @player end |
Class Method Details
._build_ary(recs, players:, penalties: false) ⇒ Object
add alias _build_all or _build_collection or ?? - why? why not?
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/fifadat/models/goal.rb', line 6 def self._build_ary( recs, players:, penalties: false ) ## note - filter out penalties (from shoot-out)!! ## min > 120 (e.g. 121, etc.) ## note - use period (more reliable) ## period 11 is PENALTY_SHOOTOUT!! if penalties == false recs = recs.select { |rec| rec['Period'] != 11 } end recs = recs.map { |h| build( h, players: players ) } ## note - sort by minutes; goals may not be sorted recs = recs.sort { |l,r| l.minute <=> r.minute } recs end |
.build(h, players:) ⇒ Object
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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/fifadat/models/goal.rb', line 26 def self.build( h, players: ) ## split into minute ## and offset (stoppage/injury time) ## e.g. 90'+11' h = errata_autofix_goal( h ) minute_str = h['Minute'] period = h['Period'] ## note - penalty shootout gets excluded upstream!! ## include penalty shootout (11) - why? why not? ## assert( [3,5,7,9].include?(period), ## "goal in period 3/5/7/9 expected; got #{h.pretty_inspect}" ) ## quick fix: ## check for weird minute 0 e.g. ## Germany-Austria 1934 if minute_str == "0'" h['Minute'] = "1'" end if minute_str.nil? || minute_str.empty? puts "!! minute in goal is nil or empty:" pp h exit 1 end minute = _build_minute( h ) rec = {} idPlayer = h['IdPlayer'] if idPlayer.nil? puts "!! no idPlayer for goal (live):" pp h ##exit 1 ## use 'N.N.' rec[ :player ] = Player::PLAYER_NIL ## 'N.N.' else rec[ :player ] = players.find!( idPlayer ) end rec[ :minute] = minute ## check for goal type (og) or (p) ## 1 - "penalty" ## 2 - "regular" ## 3 - "own goal" type = h['Type'] rec[ :pen ] = true if type == 1 rec[ :og ] = true if type == 3 new( **rec ) end |
Instance Method Details
#as_json ⇒ Object
108 109 110 111 112 113 114 115 116 117 |
# File 'lib/fifadat/models/goal.rb', line 108 def as_json(*) h = { 'name' => player.name, 'minute' => minute, } h['og'] = og if og h['pen'] = pen if pen h end |