Class: Player
Defined Under Namespace
Classes: Card
Constant Summary collapse
- PLAYER_NIL =
new( id: '<nil>', name: 'N.N.', status: nil, pos: nil )
Instance Attribute Summary collapse
-
#captain ⇒ Object
readonly
Returns the value of attribute captain.
-
#count ⇒ Object
Returns the value of attribute count.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#num ⇒ Object
readonly
Returns the value of attribute num.
-
#pos ⇒ Object
readonly
Returns the value of attribute pos.
-
#r ⇒ Object
Returns the value of attribute r.
-
#short_name ⇒ Object
readonly
Returns the value of attribute short_name.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#y ⇒ Object
Returns the value of attribute y.
-
#yr ⇒ Object
Returns the value of attribute yr.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #as_json ⇒ Object
- #bench? ⇒ Boolean
-
#initialize(id:, name:, status:, pos:, short_name: nil, captain: false, num: nil) ⇒ Player
constructor
A new instance of Player.
- #red? ⇒ Boolean
- #starter? ⇒ Boolean
-
#yellow? ⇒ Boolean
add alias yellow_card? or y? - why? why not?.
- #yellowred? ⇒ Boolean
Constructor Details
#initialize(id:, name:, status:, pos:, short_name: nil, captain: false, num: nil) ⇒ Player
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/fifadat/models/player.rb', line 150 def initialize( id:, name:, status:, ## 1 - starter, 2 - bench pos:, short_name: nil, captain: false, num: nil ## shirt/jersey number ) @id = id @name = name @short_name = name @status = status @pos = pos @captain = captain @num = num @count = 0 @y = nil @yr = nil @r = nil end |
Instance Attribute Details
#captain ⇒ Object (readonly)
Returns the value of attribute captain.
139 140 141 |
# File 'lib/fifadat/models/player.rb', line 139 def captain @captain end |
#count ⇒ Object
Returns the value of attribute count.
144 145 146 |
# File 'lib/fifadat/models/player.rb', line 144 def count @count end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
139 140 141 |
# File 'lib/fifadat/models/player.rb', line 139 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
139 140 141 |
# File 'lib/fifadat/models/player.rb', line 139 def name @name end |
#num ⇒ Object (readonly)
Returns the value of attribute num.
139 140 141 |
# File 'lib/fifadat/models/player.rb', line 139 def num @num end |
#pos ⇒ Object (readonly)
Returns the value of attribute pos.
139 140 141 |
# File 'lib/fifadat/models/player.rb', line 139 def pos @pos end |
#r ⇒ Object
Returns the value of attribute r.
144 145 146 |
# File 'lib/fifadat/models/player.rb', line 144 def r @r end |
#short_name ⇒ Object (readonly)
Returns the value of attribute short_name.
139 140 141 |
# File 'lib/fifadat/models/player.rb', line 139 def short_name @short_name end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
139 140 141 |
# File 'lib/fifadat/models/player.rb', line 139 def status @status end |
#y ⇒ Object
Returns the value of attribute y.
144 145 146 |
# File 'lib/fifadat/models/player.rb', line 144 def y @y end |
#yr ⇒ Object
Returns the value of attribute yr.
144 145 146 |
# File 'lib/fifadat/models/player.rb', line 144 def yr @yr end |
Class Method Details
._build_ary(recs) ⇒ Object
44 45 46 |
# File 'lib/fifadat/models/player.rb', line 44 def self._build_ary( recs ) recs.map { |h| build( h ) } end |
.build(h) ⇒ Object
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 99 100 101 102 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 |
# File 'lib/fifadat/models/player.rb', line 49 def self.build( h ) name = desc( h['PlayerName'] ) short_name = desc( h['ShortName'] ) if name.nil? ## "PlayerName"=>[], ## "ShortName"=>[{"Locale"=>"en-gb", "Description"=>"S. Lainer"}], ## hack: ## use shortname name = short_name end if name.nil? ## puts "name is nil:" ## pp h ## exit 1 ## report/log error/warn ## ## quick fix use N.N. for now name = 'N.N.' end ## name = norm_player( name ) ## ## todo/check - add IdCountry if available?? ## 1 - starter ## 2 - bench status = h['Status'] assert( [1,2].include?( status ), "player status 1,2 expected; got #{h.inspect}") ## what is pos 6 ?? ## e.g. ## !! ASSERT FAILED ## {"IdPlayer"=>"419456", "IdTeam"=>"32759", "ShirtNumber"=>4, "Status"=>1, ## "PlayerName"=>[{"Locale"=>"en-GB", "Description"=>"Ismaila COULIBALY"}], ## "ShortName"=>[{"Locale"=>"en-GB", "Description"=>"Ismaila COULIBALY"}], ## "Position"=>6, "PlayerPicture"=>nil, ## "FieldStatus"=>2, "LineupX"=>nil, "LineupY"=>nil} ## ## what is pos 5 ?? ## e.g. ## {"IdPlayer"=>"7czui1ih46j3zitzysxvjqjv8", "IdTeam"=>"2000019848", "ShirtNumber"=>33, ## "Status"=>1, ## "PlayerName"=>[{"Locale"=>"en-gb", "Description"=>"Maximilian Hennig"}], ## "ShortName"=>[{"Locale"=>"en-gb", "Description"=>"M. Hennig"}], ## "Position"=>5, "PlayerPicture"=>nil, "FieldStatus"=>2, "LineupX"=>nil, "LineupY"=>nil} ## ## what is pos 4 ?? ## {"IdPlayer"=>"254150", "IdTeam"=>"2000017585", "ShirtNumber"=>15, ## "Status"=>2, "SpecialStatus"=>nil, "Captain"=>false, ## "PlayerName"=>[{"Locale"=>"en-GB", "Description"=>"Nemanja RNIC"}], ## "ShortName"=>[{"Locale"=>"en-gb", "Description"=>"N. Rnić"}], ## "Position"=>4, "PlayerPicture"=>nil, "FieldStatus"=>1, "LineupX"=>nil, "LineupY"=>nil} pos = h['Position'] assert( [0,1,2,3,4,5,6].include?( pos ), "player pos 0,1,2,3,4,5,6 expected; got #{h.inspect}" ) ## 0 - is always goal keeper ## check meaning of 1 to 6 ## on website !!! ## pos is NOT (simply) matching tactics/formation (index number)!! rec = { id: h['IdPlayer'], name: name, short_name: short_name, status: status, pos: pos, } ## check for shirtNumber too num = h['ShirtNumber'] rec[:num] = num if num rec[:captain] = true if h['Captain'] new( **rec ) end |
Instance Method Details
#==(other) ⇒ Object
191 192 193 194 195 196 |
# File 'lib/fifadat/models/player.rb', line 191 def ==(other) return false unless other.is_a?(Player) self.name == other.name && self.short_name == other.short_name end |
#as_json ⇒ Object
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/fifadat/models/player.rb', line 199 def as_json(*) h = { 'name' => name, 'short_name' => short_name, 'id' => id, ## use starter|bench !!! 'status' => status, ## todo - map pos 'pos' => pos, } h['captain'] = captain if captain h['num'] = num if num h end |
#bench? ⇒ Boolean
181 |
# File 'lib/fifadat/models/player.rb', line 181 def bench?() status == 2; end |
#red? ⇒ Boolean
186 |
# File 'lib/fifadat/models/player.rb', line 186 def red?() r.is_a?(Card); end |
#starter? ⇒ Boolean
180 |
# File 'lib/fifadat/models/player.rb', line 180 def starter?() status == 1; end |
#yellow? ⇒ Boolean
add alias yellow_card? or y? - why? why not?
184 |
# File 'lib/fifadat/models/player.rb', line 184 def yellow?() y.is_a?(Card); end |
#yellowred? ⇒ Boolean
185 |
# File 'lib/fifadat/models/player.rb', line 185 def yellowred?() yr.is_a?(Card); end |