Class: Rubygoal::MatchData

Inherits:
Object
  • Object
show all
Defined in:
lib/rubygoal/match_data.rb

Defined Under Namespace

Classes: Factory, Team

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(my_score, other_score, ball_position, my_positions, other_positions, time) ⇒ MatchData

Returns a new instance of MatchData.



105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/rubygoal/match_data.rb', line 105

def initialize(my_score, other_score, ball_position, my_positions, other_positions, time)
  @me = MatchData::Team.new(
    my_score,
    result(my_score, other_score),
    my_positions
  )
  @other = MatchData::Team.new(
    other_score,
    result(other_score, my_score),
    other_positions
  )
  @time = time
  @ball = ball_position
end

Instance Attribute Details

#ballObject (readonly)

Returns the value of attribute ball.



103
104
105
# File 'lib/rubygoal/match_data.rb', line 103

def ball
  @ball
end

#meObject (readonly)

Returns the value of attribute me.



103
104
105
# File 'lib/rubygoal/match_data.rb', line 103

def me
  @me
end

#otherObject (readonly)

Returns the value of attribute other.



103
104
105
# File 'lib/rubygoal/match_data.rb', line 103

def other
  @other
end

#timeObject (readonly)

Returns the value of attribute time.



103
104
105
# File 'lib/rubygoal/match_data.rb', line 103

def time
  @time
end

Instance Method Details

#result(my_score, other_score) ⇒ Object



120
121
122
123
124
125
126
127
128
# File 'lib/rubygoal/match_data.rb', line 120

def result(my_score, other_score)
  if my_score > other_score
    :win
  elsif my_score < other_score
    :lose
  else
    :draw
  end
end