Class: Mumukit::Inspection::Expectation::V0

Inherits:
Mumukit::Inspection::Expectation show all
Defined in:
lib/mumukit/inspection/expectation.rb

Constant Summary collapse

INSPECTIONS =
%w(HasBinding HasTypeDeclaration HasTypeSignature HasVariable HasArity HasDirectRecursion
HasComposition HasComprehension HasForeach HasIf HasGuards HasConditional HasLambda HasRepeat HasWhile
HasUsage HasAnonymousVariable HasNot HasForall HasFindall)

Constants inherited from Mumukit::Inspection::Expectation

SMELLS

Instance Attribute Summary

Attributes inherited from Mumukit::Inspection::Expectation

#binding, #inspection

Instance Method Summary collapse

Methods inherited from Mumukit::Inspection::Expectation

#check!, guess_type, has_smell?, #initialize, parse, #to_h, #translate

Constructor Details

This class inherits a constructor from Mumukit::Inspection::Expectation

Instance Method Details

#as_v2Object


61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/mumukit/inspection/expectation.rb', line 61

def as_v2
  if has? 'Binding' then as_v2_declare ''
  elsif has? 'TypeDeclaration' then as_v2_declare 'TypeAlias'
  elsif has? 'TypeSignature' then as_v2_declare 'TypeSignature'
  elsif has? 'Variable' then as_v2_declare 'Variable'
  elsif has? 'Arity' then as_v2_declare "ComputationWithArity#{inspection.target.value}"
  elsif has? 'DirectRecursion' then as_v2_declare "Recursively"
  elsif has? 'Usage'
    V2.new binding, new_inspection('Uses', Mumukit::Inspection::Target.named(inspection.target.value))
  else as_v2_use
  end
end

#as_v2_declare(simple_type) ⇒ Object


82
83
84
# File 'lib/mumukit/inspection/expectation.rb', line 82

def as_v2_declare(simple_type)
  V2.new '*', new_inspection("Declares#{simple_type}", Mumukit::Inspection::Target.named(binding))
end

#as_v2_useObject


78
79
80
# File 'lib/mumukit/inspection/expectation.rb', line 78

def as_v2_use
  V2.new binding, new_inspection(inspection.type.gsub('Has', 'Uses'), nil)
end

#binding?Boolean

Returns:

  • (Boolean)

53
54
55
# File 'lib/mumukit/inspection/expectation.rb', line 53

def binding?
  binding.present?
end

#has?(simple_type) ⇒ Boolean

Returns:

  • (Boolean)

74
75
76
# File 'lib/mumukit/inspection/expectation.rb', line 74

def has?(simple_type)
  inspection.type == "Has#{simple_type}"
end

#inspection?Boolean

Returns:

  • (Boolean)

57
58
59
# File 'lib/mumukit/inspection/expectation.rb', line 57

def inspection?
  inspection.present? && INSPECTIONS.include?(inspection.type)
end

#new_inspection(type, target) ⇒ Object


86
87
88
# File 'lib/mumukit/inspection/expectation.rb', line 86

def new_inspection(type, target)
  Mumukit::Inspection.new(type, target, inspection.negated?)
end