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(HasAssignmentReturn HasCodeDuplication HasEmptyIfBranches HasMisspelledIdentifiers HasRedundantBooleanComparison HasRedundantGuards HasRedundantIf HasRedundantLambda HasRedundantLocalVariableReturn HasRedundantParameter HasRedundantReduction HasTooShortIdentifiers HasWrongCaseIdentifiers HasUnreachableCode)
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.
11 12 13 14 |
# File 'lib/mumukit/inspection/expectation.rb', line 11 def initialize(binding, inspection) @binding = binding @inspection = inspection end |
Instance Attribute Details
#binding ⇒ Object
Returns the value of attribute binding.
9 10 11 |
# File 'lib/mumukit/inspection/expectation.rb', line 9 def binding @binding end |
#inspection ⇒ Object
Returns the value of attribute inspection.
9 10 11 |
# File 'lib/mumukit/inspection/expectation.rb', line 9 def inspection @inspection end |
Class Method Details
.guess_type(expectation) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/mumukit/inspection/expectation.rb', line 29 def self.guess_type(expectation) if expectation[:inspection] =~ /(Not\:)?Has.*/ && !has_smell?(expectation[:inspection]) V0 else V2 end end |
.has_smell?(smell) ⇒ Boolean
37 38 39 |
# File 'lib/mumukit/inspection/expectation.rb', line 37 def self.has_smell?(smell) SMELLS.include? smell end |
.parse(expectation) ⇒ Object
41 42 43 44 45 |
# File 'lib/mumukit/inspection/expectation.rb', line 41 def self.parse(expectation) guess_type(expectation).new( expectation[:binding], Mumukit::Inspection.parse(expectation[:inspection])) end |
Instance Method Details
#check! ⇒ Object
16 17 18 19 |
# File 'lib/mumukit/inspection/expectation.rb', line 16 def check! raise "Wrong binding in #{to_h}" unless binding? raise "Wrong inspection #{to_h}" unless inspection? end |
#to_h ⇒ Object
25 26 27 |
# File 'lib/mumukit/inspection/expectation.rb', line 25 def to_h {binding: binding, inspection: inspection.to_s} end |
#translate(keywords = nil) ⇒ Object
21 22 23 |
# File 'lib/mumukit/inspection/expectation.rb', line 21 def translate(keywords = nil) Mumukit::Inspection::I18n.translate self, keywords end |