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
WithAnyString WithAnyNumber)

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.



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

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

Instance Attribute Details

#typeObject

Returns the value of attribute type.



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

def type
  @type
end

#valueObject

Returns the value of attribute value.



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

def value
  @value
end

Class Method Details

.parse(type, value) ⇒ Object



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

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



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

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