Class: Player

Inherits:
Object
  • Object
show all
Defined in:
lib/fbtxt-pp/models/players.rb

Defined Under Namespace

Classes: Booking, Sub

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_namesObject (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

#captainObject (readonly)

Returns the value of attribute captain.



22
23
24
# File 'lib/fbtxt-pp/models/players.rb', line 22

def captain
  @captain
end

#idObject (readonly)

Returns the value of attribute id.



22
23
24
# File 'lib/fbtxt-pp/models/players.rb', line 22

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



22
23
24
# File 'lib/fbtxt-pp/models/players.rb', line 22

def name
  @name
end

#posObject (readonly)

Returns the value of attribute pos.



22
23
24
# File 'lib/fbtxt-pp/models/players.rb', line 22

def pos
  @pos
end

#rObject (readonly)

Returns the value of attribute r.



22
23
24
# File 'lib/fbtxt-pp/models/players.rb', line 22

def r
  @r
end

#short_nameObject (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

#statusObject

e.g. 1-starter, 2-bench



30
31
32
# File 'lib/fbtxt-pp/models/players.rb', line 30

def status
  @status
end

#subObject (readonly)

Returns the value of attribute sub.



22
23
24
# File 'lib/fbtxt-pp/models/players.rb', line 22

def sub
  @sub
end

#yObject (readonly)

Returns the value of attribute y.



22
23
24
# File 'lib/fbtxt-pp/models/players.rb', line 22

def y
  @y
end

#yrObject (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?

Returns:

  • (Boolean)


78
# File 'lib/fbtxt-pp/models/players.rb', line 78

def bench?()    @status == 2; end

#captain?Boolean

Returns:

  • (Boolean)


76
# File 'lib/fbtxt-pp/models/players.rb', line 76

def captain?()  @captain; end

#keysObject

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

Returns:

  • (Boolean)


86
# File 'lib/fbtxt-pp/models/players.rb', line 86

def red?()       @r;  end

#starter?Boolean Also known as: is_starter?

Returns:

  • (Boolean)


77
# File 'lib/fbtxt-pp/models/players.rb', line 77

def starter?()  @status == 1; end

#yellow?Boolean

Returns:

  • (Boolean)


84
# File 'lib/fbtxt-pp/models/players.rb', line 84

def yellow?()    @y;  end

#yellowred?Boolean

Returns:

  • (Boolean)


85
# File 'lib/fbtxt-pp/models/players.rb', line 85

def yellowred?() @yr; end