Class: Mulang::Inspection
- Inherits:
-
Object
- Object
- Mulang::Inspection
- Includes:
- Compacted
- Defined in:
- lib/mulang/inspection.rb
Defined Under Namespace
Modules: Compacted Classes: Matcher, Target
Constant Summary collapse
- REGEXP =
Regexp.new %q{ ^(?<negation>Not:)? (?<type>[^:]+) ( :(?<matcher>WithLiteral|WithNonliteral|WithLogic|WithMath|WithFalse|WithNil|WithTrue) | :(?<matcher>WithChar|WithNumber|WithString|WithSymbol):(?<value>[^:]+) | :(?<target>[^:]+)(:(?<matcher>[^:]+)(:(?<value>[^:]+))?)? )?$}.gsub(/\s/, '')
Instance Attribute Summary collapse
-
#matcher ⇒ Object
Returns the value of attribute matcher.
-
#negated ⇒ Object
(also: #negated?)
Returns the value of attribute negated.
-
#target ⇒ Object
Returns the value of attribute target.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(type, target, negated: false, matcher: nil) ⇒ Inspection
constructor
A new instance of Inspection.
- #matcher_to_s ⇒ Object
- #negated_to_s ⇒ Object
- #target_to_s ⇒ Object
- #to_s ⇒ Object
Methods included from Compacted
Constructor Details
#initialize(type, target, negated: false, matcher: nil) ⇒ Inspection
Returns a new instance of Inspection.
23 24 25 26 27 28 |
# File 'lib/mulang/inspection.rb', line 23 def initialize(type, target, negated: false, matcher: nil) @type = type @target = target @negated = negated @matcher = matcher end |
Instance Attribute Details
#matcher ⇒ Object
Returns the value of attribute matcher.
20 21 22 |
# File 'lib/mulang/inspection.rb', line 20 def matcher @matcher end |
#negated ⇒ Object Also known as: negated?
Returns the value of attribute negated.
20 21 22 |
# File 'lib/mulang/inspection.rb', line 20 def negated @negated end |
#target ⇒ Object
Returns the value of attribute target.
20 21 22 |
# File 'lib/mulang/inspection.rb', line 20 def target @target end |
#type ⇒ Object
Returns the value of attribute type.
20 21 22 |
# File 'lib/mulang/inspection.rb', line 20 def type @type end |
Class Method Details
.parse(inspection_s) ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/mulang/inspection.rb', line 54 def self.parse(inspection_s) match = REGEXP.match inspection_s raise "Invalid inspection #{inspection_s}" unless match Inspection.new( match['type'], Mulang::Inspection::Target.parse(match['target']), matcher: Mulang::Inspection::Matcher.parse(match['matcher'], match['value']), negated: match['negation'].present?) end |
.parse_binding_name(binding_s) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/mulang/inspection.rb', line 46 def self.parse_binding_name(binding_s) if binding_s.start_with? 'Intransitive:' binding_s[13..-1] else binding_s end end |
Instance Method Details
#matcher_to_s ⇒ Object
42 43 44 |
# File 'lib/mulang/inspection.rb', line 42 def matcher_to_s matcher ? ":#{matcher.to_s}" : nil end |
#negated_to_s ⇒ Object
34 35 36 |
# File 'lib/mulang/inspection.rb', line 34 def negated_to_s negated ? 'Not:' : nil end |
#target_to_s ⇒ Object
38 39 40 |
# File 'lib/mulang/inspection.rb', line 38 def target_to_s target ? ":#{target.to_s}" : nil end |
#to_s ⇒ Object
30 31 32 |
# File 'lib/mulang/inspection.rb', line 30 def to_s "#{negated_to_s}#{type}#{target_to_s}#{matcher_to_s}" end |