Class: Fbtxt::Model::Goal
- Inherits:
-
Object
- Object
- Fbtxt::Model::Goal
- Defined in:
- lib/fbtxt/document/models/goal.rb
Overview
nested (non-freestanding) inside match (match is parent)
Instance Attribute Summary collapse
-
#minute ⇒ Object
readonly
note - 1|2 expected.
-
#name ⇒ Object
readonly
note - 1|2 expected.
-
#owngoal ⇒ Object
readonly
note - 1|2 expected.
-
#penalty ⇒ Object
readonly
note - 1|2 expected.
-
#team ⇒ Object
readonly
note - 1|2 expected.
Instance Method Summary collapse
- #==(o) ⇒ Object
-
#as_json ⇒ Object
note - EXCLUDE team 1|2 from serialize maybe remove alltogether and split into goals[[],[]] - why? why not?.
-
#initialize(team:, name:, minute: nil, owngoal: false, penalty: false) ⇒ Goal
constructor
A new instance of Goal.
-
#owngoal? ⇒ Boolean
add alias for player => name - why? why not? alias_method :player, :name.
- #penalty? ⇒ Boolean
- #pretty_print(q) ⇒ Object
- #state ⇒ Object
- #team1? ⇒ Boolean
- #team2? ⇒ Boolean
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
#minute ⇒ Object (readonly)
note - 1|2 expected
7 8 9 |
# File 'lib/fbtxt/document/models/goal.rb', line 7 def minute @minute end |
#name ⇒ Object (readonly)
note - 1|2 expected
7 8 9 |
# File 'lib/fbtxt/document/models/goal.rb', line 7 def name @name end |
#owngoal ⇒ Object (readonly)
note - 1|2 expected
7 8 9 |
# File 'lib/fbtxt/document/models/goal.rb', line 7 def owngoal @owngoal end |
#penalty ⇒ Object (readonly)
note - 1|2 expected
7 8 9 |
# File 'lib/fbtxt/document/models/goal.rb', line 7 def penalty @penalty end |
#team ⇒ Object (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_json ⇒ Object
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
16 |
# File 'lib/fbtxt/document/models/goal.rb', line 16 def owngoal?() @owngoal==true; end |
#penalty? ⇒ 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 |
#state ⇒ Object
45 46 47 48 49 |
# File 'lib/fbtxt/document/models/goal.rb', line 45 def state [@team, @name, @minute, @owngoal, @penalty ] end |
#team1? ⇒ Boolean
18 |
# File 'lib/fbtxt/document/models/goal.rb', line 18 def team1?() @team == 1; end |
#team2? ⇒ Boolean
19 |
# File 'lib/fbtxt/document/models/goal.rb', line 19 def team2?() @team == 2; end |