Class: CheckValues

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

Instance Method Summary collapse

Instance Method Details

#check_boolean(value) ⇒ Object

This function is used to check if a parameter passed to a function is a boolean, otherwise it raises an error



31
32
33
34
35
# File 'lib/chino_ruby.rb', line 31

def check_boolean(value)
    if not !!value == value
        raise ArgumentError, "{#value} must be a Boolean, got #{value.inspect}"
    end
end

#check_int(value) ⇒ Object

This function is used to check if a parameter passed to a function is an integer, otherwise it raises an error



24
25
26
27
28
# File 'lib/chino_ruby.rb', line 24

def check_int(value)
    if not value.is_a?(Integer)
        raise ArgumentError, "{#value} must be a Int, got #{value.inspect}"
    end
end

#check_json(value) ⇒ Object

This function is used to check if a parameter passed to a function can be converted to json, otherwise it raises an error



38
39
40
41
42
# File 'lib/chino_ruby.rb', line 38

def check_json(value)
    if not value.respond_to?(:to_json)
        raise ArgumentError, "{#value} cannot be converted to json!"
    end
end

#check_string(value) ⇒ Object

This function is used to check if a parameter passed to a function is a string, otherwise it raises an error



17
18
19
20
21
# File 'lib/chino_ruby.rb', line 17

def check_string(value)
    if not value.is_a?(String)
        raise ArgumentError, "{#value} must be a String, got #{value.inspect}"
    end
end