Class: Mulang::Inspection::Matcher

Inherits:
Object
  • Object
show all
Includes:
Compacted
Defined in:
lib/mulang/inspection/matcher.rb

Constant Summary collapse

TYPES =
%w(
WithAnything WithChar WithFalse WithLiteral
WithLogic WithMath WithNil WithNonliteral
WithNumber WithReference WithString
WithSymbol WithTrue)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Compacted

#as_json

Constructor Details

#initialize(type, value = nil) ⇒ Matcher

Returns a new instance of Matcher.



12
13
14
15
# File 'lib/mulang/inspection/matcher.rb', line 12

def initialize(type, value=nil)
  @type = type
  @value = value
end

Instance Attribute Details

#typeObject

Returns the value of attribute type.



10
11
12
# File 'lib/mulang/inspection/matcher.rb', line 10

def type
  @type
end

#valueObject

Returns the value of attribute value.



10
11
12
# File 'lib/mulang/inspection/matcher.rb', line 10

def value
  @value
end

Class Method Details

.parse(type, value) ⇒ Object



21
22
23
24
25
# File 'lib/mulang/inspection/matcher.rb', line 21

def self.parse(type, value)
  return nil unless type
  raise "Invalid matcher #{type}" unless type.in? TYPES
  new type.underscore.to_sym, value
end

Instance Method Details

#to_sObject



17
18
19
# File 'lib/mulang/inspection/matcher.rb', line 17

def to_s
  "#{type.to_s.camelcase}#{value ? ":#{value}" : nil}"
end