Class: DiffMatcher::Matcher
- Inherits:
-
Object
- Object
- DiffMatcher::Matcher
- Defined in:
- lib/diff_matcher/difference.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#expecteds ⇒ Object
readonly
Returns the value of attribute expecteds.
Class Method Summary collapse
Instance Method Summary collapse
- #diff(actual, opts = {}) ⇒ Object
- #expected(e, actual) ⇒ Object
- #expected_opts(e) ⇒ Object
-
#initialize(expected, opts = {}) ⇒ Matcher
constructor
A new instance of Matcher.
- #|(other) ⇒ Object
Constructor Details
#initialize(expected, opts = {}) ⇒ Matcher
Returns a new instance of Matcher.
17 18 19 20 |
# File 'lib/diff_matcher/difference.rb', line 17 def initialize(expected, opts={}) @expecteds = [expected] @expected_opts = {expected => opts} end |
Instance Attribute Details
#expecteds ⇒ Object (readonly)
Returns the value of attribute expecteds.
11 12 13 |
# File 'lib/diff_matcher/difference.rb', line 11 def expecteds @expecteds end |
Class Method Details
.[](*expecteds) ⇒ Object
13 14 15 |
# File 'lib/diff_matcher/difference.rb', line 13 def self.[](*expecteds) expecteds.inject(nil) { |obj, e| obj ? obj | new(e) : new(e) } end |
Instance Method Details
#diff(actual, opts = {}) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/diff_matcher/difference.rb', line 35 def diff(actual, opts={}) difs = [] matched = @expecteds.any? { |e| d = DiffMatcher::Difference.new(expected(e, actual), actual, opts.merge(expected_opts(e))) unless d.matching? difs << [ d.dif_count, d.dif ] end d.matching? } unless matched count, dif = difs.sort.last dif end end |
#expected(e, actual) ⇒ Object
27 28 29 |
# File 'lib/diff_matcher/difference.rb', line 27 def expected(e, actual) e end |
#expected_opts(e) ⇒ Object
31 32 33 |
# File 'lib/diff_matcher/difference.rb', line 31 def expected_opts(e) @expected_opts.fetch(e, {}) end |
#|(other) ⇒ Object
22 23 24 25 |
# File 'lib/diff_matcher/difference.rb', line 22 def |(other) #"(#{expecteds.join(",")}|#{other.expecteds.join(",")})" tap { @expecteds += other.expecteds } end |