Class: Rbcalc::Engine

Inherits:
Object
  • Object
show all
Defined in:
lib/rbcalc/engine.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Engine

Returns a new instance of Engine.



15
16
17
# File 'lib/rbcalc/engine.rb', line 15

def initialize params = {}
  params.map { |k,v| self.send(:"#{k}=",v) }
end

Instance Attribute Details

#handsObject

Returns the value of attribute hands.



13
14
15
# File 'lib/rbcalc/engine.rb', line 13

def hands
  @hands
end

#leaderObject

Returns the value of attribute leader.



13
14
15
# File 'lib/rbcalc/engine.rb', line 13

def leader
  @leader
end

#playedObject

Returns the value of attribute played.



13
14
15
# File 'lib/rbcalc/engine.rb', line 13

def played
  @played
end

#tricks_madeObject

Returns the value of attribute tricks_made.



13
14
15
# File 'lib/rbcalc/engine.rb', line 13

def tricks_made
  @tricks_made
end

#trump_suitObject

Returns the value of attribute trump_suit.



13
14
15
# File 'lib/rbcalc/engine.rb', line 13

def trump_suit
  @trump_suit
end

Instance Method Details

#parse!Object



19
20
21
22
23
24
25
# File 'lib/rbcalc/engine.rb', line 19

def parse!
  if hands.nil? || hands.empty? || leader.nil? || trump_suit.nil?
    raise ArgumentError, 'Rbcalc needs at least the hands, dealer direction and trump suit'
  end
  
  self.tricks_made = solve(hands, "#{played.to_s} e", trump_suit, leader)
end