Class: GameShuffleCards::ValidateGame
- Inherits:
-
Object
- Object
- GameShuffleCards::ValidateGame
- Defined in:
- lib/game_shuffle_cards/validate_game.rb
Overview
validation to secure the inputs of the Game
Class Method Summary (collapse)
-
+ (Object) parse_and_validate(players, cards_per_player)
Given two values String or Integer, checks whether they are valid in a context Game then return the integers values or raise an exception.
-
+ (Object) parse_and_validate_players(players)
Validates whether the amount and type of players are right.
Class Method Details
+ (Object) parse_and_validate(players, cards_per_player)
Given two values String or Integer, checks whether they are valid in a context Game then return the integers values or raise an exception
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/game_shuffle_cards/validate_game.rb', line 12 def parse_and_validate(players, cards_per_player) begin players = Integer(players) cards_per_player= Integer(cards_per_player) rescue raise TypeError end raise GameShuffleCards::ToManyPlayersError if players > GameShuffleCards::Game::MAXIMUN_PLAYERS raise GameShuffleCards::NotEnoughPlayersError if players < GameShuffleCards::Game::MINIMUN_PLAYERS raise GameShuffleCards::ToManyCardsPerPlayerError if cards_per_player > GameShuffleCards::Game::TOTAL_CARDS raise GameShuffleCards::NotEnoughCardsPerPlayersError if cards_per_player < GameShuffleCards::Game::MINIMUN_CARDS raise GameShuffleCards::TooManyCardsDemandedError if (players * cards_per_player) > GameShuffleCards::Game::TOTAL_CARDS [players,cards_per_player] end |
+ (Object) parse_and_validate_players(players)
Validates whether the amount and type of players are right. Otherwise raise an exception
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/game_shuffle_cards/validate_game.rb', line 31 def parse_and_validate_players(players) begin players = Integer(players) rescue raise TypeError end raise GameShuffleCards::ToManyPlayersError if players > GameShuffleCards::Game::MAXIMUN_PLAYERS raise GameShuffleCards::NotEnoughPlayersError if players < GameShuffleCards::Game::MINIMUN_PLAYERS players end |