Class: Penalty
Instance Attribute Summary collapse
-
#more ⇒ Object
readonly
Returns the value of attribute more.
-
#player ⇒ Object
readonly
Returns the value of attribute player.
-
#score ⇒ Object
readonly
Returns the value of attribute score.
-
#scored ⇒ Object
readonly
Returns the value of attribute scored.
-
#team ⇒ Object
readonly
Returns the value of attribute team.
Class Method Summary collapse
- ._build_ary(recs, players:, team1_id:, team2_id:) ⇒ Object
- .build(h, players:, team1_id:, team2_id:) ⇒ Object
Instance Method Summary collapse
- #as_json ⇒ Object
-
#initialize(player:, team:, score:, scored:, more: {}) ⇒ Penalty
constructor
A new instance of Penalty.
Constructor Details
#initialize(player:, team:, score:, scored:, more: {}) ⇒ Penalty
Returns a new instance of Penalty.
142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/fifadat/models/penalty.rb', line 142 def initialize( player:, team:, score:, scored:, more: {} ) @player = player @team = team ## e.g. 1|2 @score = score ## e.g. [1,0] @scored = scored ## e.g. true|false @more = more end |
Instance Attribute Details
#more ⇒ Object (readonly)
Returns the value of attribute more.
138 139 140 |
# File 'lib/fifadat/models/penalty.rb', line 138 def more @more end |
#player ⇒ Object (readonly)
Returns the value of attribute player.
138 139 140 |
# File 'lib/fifadat/models/penalty.rb', line 138 def player @player end |
#score ⇒ Object (readonly)
Returns the value of attribute score.
138 139 140 |
# File 'lib/fifadat/models/penalty.rb', line 138 def score @score end |
#scored ⇒ Object (readonly)
Returns the value of attribute scored.
138 139 140 |
# File 'lib/fifadat/models/penalty.rb', line 138 def scored @scored end |
#team ⇒ Object (readonly)
Returns the value of attribute team.
138 139 140 |
# File 'lib/fifadat/models/penalty.rb', line 138 def team @team end |
Class Method Details
._build_ary(recs, players:, team1_id:, team2_id:) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/fifadat/models/penalty.rb', line 103 def self._build_ary( recs, players:, team1_id:, team2_id: ) ################ ## type: ## check for "old/legacy" format used where? ## not using period 11 ??? ## incl. weirdo format with ## 6 - penalty awarded ## 0 - goal or 60 - penalty missed! ## ## 2 - yellow card ## 3 - red card ## 7 - start time ## 8 - end time recs = recs.select do |h| if h['Period'] == 11 ## penalty shoot-out assert( [0,2,3,6,7,8,41,46,51,60,65].include?( h['Type'] ), "expected event type 2/3/7/8/41/46/51/60/65 for pens; got #{h.pretty_inspect}" ) [0,41,46,51,60,65].include?( h['Type'] ) ? true : false else false end end recs = recs.map { |h| build( h, players: players, team1_id: team1_id, team2_id: team2_id ) } recs end |
.build(h, players:, team1_id:, team2_id:) ⇒ 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 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/fifadat/models/penalty.rb', line 26 def self.build( h, players:, team1_id:, team2_id: ) ## note - do NOT care about minutes in penalty shootout ## check for period == 11 (penalty shotout!!) ## period = h['Period'] ########## ## 0 - goal (when penalty awarded used before) ## 41 - penalty goal ## ## 46 - penalty missed ## Dragan STOJKOVIC (Yugoslavia) rattles the crossbar from the spot! ## 51 - penalty missed ## JULIO CESAR (Brazil) hits the post from the spot! ## 60 - penalty missed ## COMAN (France) sees his penalty saved by the goalkeeper. ## Maxime BOSSIS (France) misses from the penalty spot! and many more ## 65 - penalty missed ## TCHOUAMENI (France) misses from the penalty spot! type = h['Type'] ## (timeline) event type assert( [0,41,46,51,60,65].include?(type), "event type 0/41/46/51/60/65 expected; got #{type}") team = if h['IdTeam'] == team1_id 1 elsif h['IdTeam'] == team2_id 2 else assert( false, "team1/2_id #{team1_id/team2_id} expected; got #{h.pretty_inspect}") end rec = { team: team, ## 1|2 score: [h['HomePenaltyGoals'], h['AwayPenaltyGoals']], scored: [0,41].include?( type ) ? true : false, } idPlayer = h['IdPlayer'] =begin -- try IdSubPlayer - why? why not? IdSubPlayer is goalkeeper!!! ## what is SubPlayer/SubTeam in event?? !! no idPlayer for penaltyl! {"EventId"=>"17807200001266", "IdTeam"=>"1884426", "IdSubPlayer"=>"408948", "IdSubTeam"=>"1897032", =end if idPlayer.nil? puts "!! no idPlayer for penalty (timeline event):" pp h ## exit 1 ## use 'N.N.' rec[ :player ] = Player::PLAYER_NIL else rec[ :player ] = players.find!( idPlayer ) end rec[:more] = { type: type, desc: desc(h['EventDescription']) ## add event desc too - why? why not? } new( **rec ) end |
Instance Method Details
#as_json ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/fifadat/models/penalty.rb', line 155 def as_json(*) h = { 'name' => player.name, 'score' => score, 'scored' => scored, 'team' => team, } h['more'] = more unless more.empty? h end |