Class: PrintPrimesTable::Validators::ErrorMessage

Inherits:
Object
  • Object
show all
Defined in:
lib/print_primes_table/validators/error_message.rb

Overview

An intance contains te error_type and a message to the user

Author:

Constant Summary

MESSAGES =
{

	:command_wrong_arguments => "the program allowed %{max} argument maximun, you typed %{argument_num}",
	:command_wrong_type_arguments => "Sorry, %{argument} is not an integer",
	:less_than_min => "The minimun quantity is %{min}, so %{argument} is not valid"
}

Instance Method Summary (collapse)

Constructor Details

- (ErrorMessage) initialize(error_type = :invalid, args = {}, content = nil)

initialize the message

Parameters:

  • content (String) (defaults to: nil)

    text message to the user

  • error_type (Symbol) (defaults to: :invalid)

    to qualifies the error

  • args (Hash) (defaults to: {})

    to include params in the response



16
17
18
19
20
21
22
23
24
# File 'lib/print_primes_table/validators/error_message.rb', line 16

def initialize(error_type = :invalid,  args = {}, content = nil)
	unless content
		@content=MESSAGES[error_type]
	else
		@content = content
	end
	@error_type = error_type
	@args = args
end

Instance Method Details

- (Object) show_content

Returns text message [String] it could contain arguments

Returns:

  • text message [String] it could contain arguments



26
27
28
# File 'lib/print_primes_table/validators/error_message.rb', line 26

def show_content
	"\n" + @content % @args
end