Class: Player
- Inherits:
-
Object
- Object
- Player
- Defined in:
- lib/fbtxt-pp/models/players.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#alt_names ⇒ Object
readonly
Returns the value of attribute alt_names.
-
#captain ⇒ Object
readonly
Returns the value of attribute captain.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#pos ⇒ Object
readonly
Returns the value of attribute pos.
-
#r ⇒ Object
readonly
Returns the value of attribute r.
-
#short_name ⇒ Object
readonly
Returns the value of attribute short_name.
-
#status ⇒ Object
e.g.
-
#sub ⇒ Object
readonly
Returns the value of attribute sub.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
-
#yr ⇒ Object
readonly
Returns the value of attribute yr.
Class Method Summary collapse
Instance Method Summary collapse
- #add_red(minute: nil) ⇒ Object
-
#add_sub(player:, minute: nil) ⇒ Object
(nested) class Sub.
-
#add_yellow(minute: nil) ⇒ Object
(nested) booking record/struct.
- #add_yellowred(minute: nil) ⇒ Object
- #bench? ⇒ Boolean (also: #is_bench?)
- #captain? ⇒ Boolean
-
#initialize(name:, short_name: nil, captain: false, id: nil) ⇒ Player
constructor
A new instance of Player.
-
#keys ⇒ Object
get lookup keys (id+name+alt_names).
- #red? ⇒ Boolean
- #starter? ⇒ Boolean (also: #is_starter?)
- #yellow? ⇒ Boolean
- #yellowred? ⇒ Boolean
Constructor Details
#initialize(name:, short_name: nil, captain: false, id: nil) ⇒ Player
Returns a new instance of Player.
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 |
# File 'lib/fbtxt-pp/models/players.rb', line 34 def initialize( name:, short_name: nil, captain: false, id: nil ) @alt_names = [] norm = norm_name( name ) if norm != name puts " NORM PLAYER NAME >#{name}< => >#{norm}<" @alt_names << name name = norm end @name = name @short_name = short_name @captain = captain @id = id @pos = nil ## fix-fix-fix - add pos(ition) @status = nil ## e.g. starter/bench|sub/etc. ## todo/check - add "generic" sentoff for pre-cards era - why? why not? @y, @yr, @r = nil,nil,nil @sub = nil end |
Instance Attribute Details
#alt_names ⇒ Object (readonly)
Returns the value of attribute alt_names.
22 23 24 |
# File 'lib/fbtxt-pp/models/players.rb', line 22 def alt_names @alt_names end |
#captain ⇒ Object (readonly)
Returns the value of attribute captain.
22 23 24 |
# File 'lib/fbtxt-pp/models/players.rb', line 22 def captain @captain end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
22 23 24 |
# File 'lib/fbtxt-pp/models/players.rb', line 22 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
22 23 24 |
# File 'lib/fbtxt-pp/models/players.rb', line 22 def name @name end |
#pos ⇒ Object (readonly)
Returns the value of attribute pos.
22 23 24 |
# File 'lib/fbtxt-pp/models/players.rb', line 22 def pos @pos end |
#r ⇒ Object (readonly)
Returns the value of attribute r.
22 23 24 |
# File 'lib/fbtxt-pp/models/players.rb', line 22 def r @r end |
#short_name ⇒ Object (readonly)
Returns the value of attribute short_name.
22 23 24 |
# File 'lib/fbtxt-pp/models/players.rb', line 22 def short_name @short_name end |
#status ⇒ Object
e.g. 1-starter, 2-bench
30 31 32 |
# File 'lib/fbtxt-pp/models/players.rb', line 30 def status @status end |
#sub ⇒ Object (readonly)
Returns the value of attribute sub.
22 23 24 |
# File 'lib/fbtxt-pp/models/players.rb', line 22 def sub @sub end |
#y ⇒ Object (readonly)
Returns the value of attribute y.
22 23 24 |
# File 'lib/fbtxt-pp/models/players.rb', line 22 def y @y end |
#yr ⇒ Object (readonly)
Returns the value of attribute yr.
22 23 24 |
# File 'lib/fbtxt-pp/models/players.rb', line 22 def yr @yr end |
Class Method Details
.build(h) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/fbtxt-pp/models/players.rb', line 5 def self.build( h ) ## rec = { id: h['IdPlayer'], ## ## status: h['Status'], ## pos: h['Position'], new( name: h['name'], short_name: h['short_name'], captain: h['captain'], id: h['id'] ) end |
Instance Method Details
#add_red(minute: nil) ⇒ Object
99 |
# File 'lib/fbtxt-pp/models/players.rb', line 99 def add_red( minute: nil ) @r = Booking.new( minute: minute ); end |
#add_sub(player:, minute: nil) ⇒ Object
(nested) class Sub
113 114 115 116 |
# File 'lib/fbtxt-pp/models/players.rb', line 113 def add_sub( player:, minute: nil ) @sub = Sub.new( player: player, minute: minute ) end |
#add_yellow(minute: nil) ⇒ Object
(nested) booking record/struct
97 |
# File 'lib/fbtxt-pp/models/players.rb', line 97 def add_yellow( minute: nil ) @y = Booking.new( minute: minute ); end |
#add_yellowred(minute: nil) ⇒ Object
98 |
# File 'lib/fbtxt-pp/models/players.rb', line 98 def add_yellowred( minute: nil ) @yr = Booking.new( minute: minute ); end |
#bench? ⇒ Boolean Also known as: is_bench?
78 |
# File 'lib/fbtxt-pp/models/players.rb', line 78 def bench?() @status == 2; end |
#captain? ⇒ Boolean
76 |
# File 'lib/fbtxt-pp/models/players.rb', line 76 def captain?() @captain; end |
#keys ⇒ Object
get lookup keys (id+name+alt_names)
63 64 65 66 67 68 69 70 71 |
# File 'lib/fbtxt-pp/models/players.rb', line 63 def keys keys = [] keys << @id if @id keys << slugify(@name) keys += @alt_names.map {|name| slugify(name)} unless @alt_names.empty? ## note - make sure keys are unique keys.uniq end |
#red? ⇒ Boolean
86 |
# File 'lib/fbtxt-pp/models/players.rb', line 86 def red?() @r; end |
#starter? ⇒ Boolean Also known as: is_starter?
77 |
# File 'lib/fbtxt-pp/models/players.rb', line 77 def starter?() @status == 1; end |
#yellow? ⇒ Boolean
84 |
# File 'lib/fbtxt-pp/models/players.rb', line 84 def yellow?() @y; end |
#yellowred? ⇒ Boolean
85 |
# File 'lib/fbtxt-pp/models/players.rb', line 85 def yellowred?() @yr; end |