Class: Mulang::Inspection::Matcher

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

Constant Summary collapse

TYPES =
%w(WithChar WithFalse WithLiteral WithLogic WithMath WithNil WithNonliteral WithNumber 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.



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

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

Instance Attribute Details

#typeObject

Returns the value of attribute type.



6
7
8
# File 'lib/mulang/inspection/matcher.rb', line 6

def type
  @type
end

#valueObject

Returns the value of attribute value.



6
7
8
# File 'lib/mulang/inspection/matcher.rb', line 6

def value
  @value
end

Class Method Details

.parse(type, value) ⇒ Object



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

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



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

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