Class: Mumukit::Inspection::Expectation
- Inherits:
-
Object
- Object
- Mumukit::Inspection::Expectation
- Defined in:
- lib/mumukit/inspection/expectation.rb
Defined Under Namespace
Constant Summary collapse
- SMELLS =
%w(DiscardsExceptions DoesConsolePrint DoesNullTest DoesTypeTest HasAssignmentReturn HasCodeDuplication HasEmptyIfBranches HasMisspelledIdentifiers HasRedundantBooleanComparison HasRedundantGuards HasRedundantIf HasRedundantLambda HasRedundantLocalVariableReturn HasRedundantParameter HasRedundantReduction HasTooShortIdentifiers HasUnreachableCode HasWrongCaseIdentifiers IsLongCode ReturnsNull UsesCut UsesFail UsesUnificationOperator)
Instance Attribute Summary collapse
-
#binding ⇒ Object
Returns the value of attribute binding.
-
#inspection ⇒ Object
Returns the value of attribute inspection.
Class Method Summary collapse
Instance Method Summary collapse
- #check! ⇒ Object
-
#initialize(binding, inspection) ⇒ Expectation
constructor
A new instance of Expectation.
- #to_h ⇒ Object
- #translate(keywords = nil) ⇒ Object
Constructor Details
#initialize(binding, inspection) ⇒ Expectation
Returns a new instance of Expectation.
12 13 14 15 |
# File 'lib/mumukit/inspection/expectation.rb', line 12 def initialize(binding, inspection) @binding = binding @inspection = inspection end |
Instance Attribute Details
#binding ⇒ Object
Returns the value of attribute binding.
10 11 12 |
# File 'lib/mumukit/inspection/expectation.rb', line 10 def binding @binding end |
#inspection ⇒ Object
Returns the value of attribute inspection.
10 11 12 |
# File 'lib/mumukit/inspection/expectation.rb', line 10 def inspection @inspection end |
Class Method Details
.guess_type(expectation) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/mumukit/inspection/expectation.rb', line 30 def self.guess_type(expectation) if expectation[:inspection] =~ /(Not\:)?Has.*/ && !has_smell?(expectation[:inspection]) V0 else V2 end end |
.has_smell?(smell) ⇒ Boolean
38 39 40 |
# File 'lib/mumukit/inspection/expectation.rb', line 38 def self.has_smell?(smell) SMELLS.include? smell end |
.parse(expectation) ⇒ Object
42 43 44 45 46 |
# File 'lib/mumukit/inspection/expectation.rb', line 42 def self.parse(expectation) guess_type(expectation).new( expectation[:binding], Mumukit::Inspection.parse(expectation[:inspection])) end |
Instance Method Details
#check! ⇒ Object
17 18 19 20 |
# File 'lib/mumukit/inspection/expectation.rb', line 17 def check! raise "Wrong binding in #{to_h}" unless binding? raise "Wrong inspection #{to_h}" unless inspection? end |
#to_h ⇒ Object
26 27 28 |
# File 'lib/mumukit/inspection/expectation.rb', line 26 def to_h {binding: binding, inspection: inspection.to_s} end |
#translate(keywords = nil) ⇒ Object
22 23 24 |
# File 'lib/mumukit/inspection/expectation.rb', line 22 def translate(keywords = nil) Mumukit::Inspection::I18n.translate self, keywords end |