Class: JsonExpressions::Matcher

Inherits:
Object
  • Object
show all
Defined in:
lib/json_expressions/matcher.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json, options = {}) ⇒ Matcher

Returns a new instance of Matcher.

[View source]

41
42
43
44
45
46
# File 'lib/json_expressions/matcher.rb', line 41

def initialize(json, options = {})
  defaults = {}
  @json = json
  @options = defaults.merge(options)
  reset!
end

Class Attribute Details

.assume_strict_arraysObject

JsonExpressions::Matcher.assume_strict_arrays (Boolean)

By default, reject arrays with extra elements when not specified
Default: true

22
23
24
# File 'lib/json_expressions/matcher.rb', line 22

def assume_strict_arrays
  @assume_strict_arrays
end

.assume_strict_hashesObject

JsonExpressions::Matcher.assume_strict_hashes (Boolean)

By default, reject hashes with extra keys when not specified
Default: true

34
35
36
# File 'lib/json_expressions/matcher.rb', line 34

def assume_strict_hashes
  @assume_strict_hashes
end

.assume_unordered_arraysObject

JsonExpressions::Matcher.assume_unordered_arrays (Boolean)

By default, assume arrays are unordered when not specified
Default: true

16
17
18
# File 'lib/json_expressions/matcher.rb', line 16

def assume_unordered_arrays
  @assume_unordered_arrays
end

.assume_unordered_hashesObject

JsonExpressions::Matcher.assume_unordered_hashes (Boolean)

By default, assume hashes are unordered when not specified
Default: true

28
29
30
# File 'lib/json_expressions/matcher.rb', line 28

def assume_unordered_hashes
  @assume_unordered_hashes
end

.skip_triple_equal_onObject

JsonExpressions::Matcher.skip_triple_equal_on (Array)

An array of classes and modules with undesirable `===` behavior
Default: []

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

def skip_triple_equal_on
  @skip_triple_equal_on
end

Instance Attribute Details

#capturesObject (readonly)

Returns the value of attribute captures.


39
40
41
# File 'lib/json_expressions/matcher.rb', line 39

def captures
  @captures
end

#last_errorObject (readonly)

Returns the value of attribute last_error.


38
39
40
# File 'lib/json_expressions/matcher.rb', line 38

def last_error
  @last_error
end

Instance Method Details

#=~(other) ⇒ Object Also known as: match

[View source]

48
49
50
51
# File 'lib/json_expressions/matcher.rb', line 48

def =~(other)
  reset!
  match_json('(JSON ROOT)', @json, other)
end

#to_sObject

[View source]

55
56
57
# File 'lib/json_expressions/matcher.rb', line 55

def to_s
  @json.to_s
end