Class: RspecApiDocs::After::TypeChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec_api_docs/after/type_checker.rb

Constant Summary collapse

UnknownType =
Class.new(BaseError)
TypeError =
Class.new(BaseError)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, value:) ⇒ TypeChecker


13
14
15
16
# File 'lib/rspec_api_docs/after/type_checker.rb', line 13

def initialize(type:, value:)
  @type = type
  @value = value
end

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type


7
8
9
# File 'lib/rspec_api_docs/after/type_checker.rb', line 7

def type
  @type
end

#valueObject (readonly)

Returns the value of attribute value


7
8
9
# File 'lib/rspec_api_docs/after/type_checker.rb', line 7

def value
  @value
end

Class Method Details

.call(*args) ⇒ Object


9
10
11
# File 'lib/rspec_api_docs/after/type_checker.rb', line 9

def self.call(*args)
  new(*args).check
end

Instance Method Details

#checkObject


18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rspec_api_docs/after/type_checker.rb', line 18

def check
  case type
  when /integer/i
    is_integer?(value) or raise_type_error
  when /float/i
    is_float?(value) or raise_type_error
  when /boolean/i
    is_bool?(value) or raise_type_error
  when /string/i
    # NO OP
  else
    raise UnknownType, "unknown type #{type.inspect}"
  end
end