Class: PrismChecker::ExpectationClassifier

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

Constant Summary collapse

EXPECTATIONS_MAP =
[
  %i[invisible invisible?],
  %i[visible visible?],
  %i[empty empty?],
  %i[string string?],
  %i[regexp regexp?],
  %i[array array?],
  %i[hash hash?],
  %i[boolean boolean?],
  %i[number number?]
].freeze

Class Method Summary collapse

Class Method Details

.array?(expectation) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/prism_checker/expectation_classifier.rb', line 46

def self.array?(expectation)
  expectation.is_a?(Array)
end

.boolean?(expectation) ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/prism_checker/expectation_classifier.rb', line 54

def self.boolean?(expectation)
  expectation.is_a?(TrueClass) || expectation.is_a?(FalseClass)
end

.classify(expectation) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/prism_checker/expectation_classifier.rb', line 17

def self.classify(expectation)
  EXPECTATIONS_MAP.each do |data|
    type, probe = data
    return type if send(probe, expectation)
  end

  :other
end

.empty?(expectation) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/prism_checker/expectation_classifier.rb', line 34

def self.empty?(expectation)
  expectation == :empty
end

.hash?(expectation) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/prism_checker/expectation_classifier.rb', line 50

def self.hash?(expectation)
  expectation.is_a?(Hash)
end

.invisible?(expectation) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/prism_checker/expectation_classifier.rb', line 26

def self.invisible?(expectation)
  expectation == :invisible
end

.number?(expectation) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/prism_checker/expectation_classifier.rb', line 58

def self.number?(expectation)
  expectation.is_a?(Integer)
end

.regexp?(expectation) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/prism_checker/expectation_classifier.rb', line 42

def self.regexp?(expectation)
  expectation.is_a?(Regexp)
end

.string?(expectation) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/prism_checker/expectation_classifier.rb', line 38

def self.string?(expectation)
  expectation.is_a?(String)
end

.visible?(expectation) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/prism_checker/expectation_classifier.rb', line 30

def self.visible?(expectation)
  expectation == :visible
end