Class: Eapi::TypeChecker

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(given_type, allow_raw = false) ⇒ TypeChecker

Returns a new instance of TypeChecker.



18
19
20
21
# File 'lib/eapi/type_checker.rb', line 18

def initialize(given_type, allow_raw = false)
  @given_type = given_type
  @allow_raw  = allow_raw
end

Instance Attribute Details

#allow_rawObject (readonly)

Returns the value of attribute allow_raw.



16
17
18
# File 'lib/eapi/type_checker.rb', line 16

def allow_raw
  @allow_raw
end

#given_typeObject (readonly)

Returns the value of attribute given_type.



16
17
18
# File 'lib/eapi/type_checker.rb', line 16

def given_type
  @given_type
end

Class Method Details

.constant_for_type(type) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/eapi/type_checker.rb', line 4

def self.constant_for_type(type)
  if type.kind_of? Module
    type
  else
    begin
      type.to_s.constantize
    rescue NameError
      nil
    end
  end
end

Instance Method Details

#is_valid_type?(value) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/eapi/type_checker.rb', line 23

def is_valid_type?(value)
  value.nil? || valid_raw?(value) || is_same_type?(value) || poses_as_type?(value)
end