Class: Fbtxt::Model::Goal

Inherits:
Object
  • Object
show all
Defined in:
lib/fbtxt/document/models/goal.rb

Overview

nested (non-freestanding) inside match (match is parent)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(team:, name:, minute: nil, owngoal: false, penalty: false) ⇒ Goal

Returns a new instance of Goal.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/fbtxt/document/models/goal.rb', line 22

def initialize( team:,
                name:,
                minute:  nil,
                owngoal: false,
                penalty: false
              )
  @team    = team     # 1|2
  @name    = name

  ## note - auto-convert to our own Minute format
  ##        is obj/incl. (optional) offset/injury time!!
  @minute =  if minute.is_a?( RaccMatchParser::Minute )
                      Minute.new( m:      minute.m,
                                  offset: minute.offset,
                                  secs:   minute.secs )
                 else
                  minute
                 end

  @owngoal = owngoal
  @penalty = penalty
end

Instance Attribute Details

#minuteObject (readonly)

note - 1|2 expected



7
8
9
# File 'lib/fbtxt/document/models/goal.rb', line 7

def minute
  @minute
end

#nameObject (readonly)

note - 1|2 expected



7
8
9
# File 'lib/fbtxt/document/models/goal.rb', line 7

def name
  @name
end

#owngoalObject (readonly)

note - 1|2 expected



7
8
9
# File 'lib/fbtxt/document/models/goal.rb', line 7

def owngoal
  @owngoal
end

#penaltyObject (readonly)

note - 1|2 expected



7
8
9
# File 'lib/fbtxt/document/models/goal.rb', line 7

def penalty
  @penalty
end

#teamObject (readonly)

note - 1|2 expected



7
8
9
# File 'lib/fbtxt/document/models/goal.rb', line 7

def team
  @team
end

Instance Method Details

#==(o) ⇒ Object



51
52
53
# File 'lib/fbtxt/document/models/goal.rb', line 51

def ==(o)
  o.class == self.class && o.state == state
end

#as_jsonObject

note - EXCLUDE team 1|2 from serialize maybe remove alltogether and split into goals[[],[]] - why? why not?



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/fbtxt/document/models/goal.rb', line 69

def as_json(*)
    h = { 'name'  => name  }

=begin
      ## note - use a string for minutes for now
      ##           allows e.g.  45+2 etc. too
      minute_str  = "#{goal.minute}"
      minute_str += "+#{goal.offset}"   if goal.offset

      node['minute']  = minute_str
=end

    h['minute'] = minute.to_s    if minute

    h['owngoal'] = true         if owngoal?
    h['penalty'] = true         if penalty?

    h
end

#owngoal?Boolean

add alias for player => name - why? why not? alias_method :player, :name

Returns:

  • (Boolean)


16
# File 'lib/fbtxt/document/models/goal.rb', line 16

def owngoal?() @owngoal==true; end

#penalty?Boolean

Returns:

  • (Boolean)


17
# File 'lib/fbtxt/document/models/goal.rb', line 17

def penalty?() @penalty==true; end

#pretty_print(q) ⇒ Object



55
56
57
58
59
60
61
62
63
64
# File 'lib/fbtxt/document/models/goal.rb', line 55

def pretty_print( q )
  q.group( 4, '<Goal ', '>') do        ##  group( indent, open, close)
    q.text( name )
    q.text( " #{@minute}" )    if @minute

    q.text( "(og)" )  if @owngoal
    q.text( "(p)" )   if @penalty
    q.text( " for #{@team}" )      ### team 1 or 2 - use home/away
  end
end

#stateObject



45
46
47
48
49
# File 'lib/fbtxt/document/models/goal.rb', line 45

def state
  [@team,
   @name, @minute, @owngoal, @penalty
   ]
end

#team1?Boolean

Returns:

  • (Boolean)


18
# File 'lib/fbtxt/document/models/goal.rb', line 18

def team1?()   @team == 1; end

#team2?Boolean

Returns:

  • (Boolean)


19
# File 'lib/fbtxt/document/models/goal.rb', line 19

def team2?()   @team == 2; end