Class: ScraperWiki::API::Matchers::FieldKeyMatcher
- Inherits:
-
FieldMatcher
- Object
- CustomMatcher
- DatastoreMatcher
- FieldMatcher
- ScraperWiki::API::Matchers::FieldKeyMatcher
- Defined in:
- lib/scraperwiki-api/matchers.rb
Direct Known Subclasses
Instance Method Summary collapse
- #difference(v) ⇒ Object
- #failure_predicate ⇒ Object
- #match?(v) ⇒ Boolean
- #negative_failure_predicate ⇒ Object
Methods inherited from FieldMatcher
#at, #blank?, #failure_description, #in, #matcher, #matches, #mismatches, #negative_failure_description
Methods inherited from DatastoreMatcher
#does_not_match?, #failure_description, #failure_message, #failure_size, #failures, #items, #matches, #matches?, #mismatches, #negative_failure_description, #negative_failure_message
Methods inherited from CustomMatcher
#does_not_match?, #failure_message, #initialize, #matches?, #negative_failure_message
Constructor Details
This class inherits a constructor from ScraperWiki::API::Matchers::CustomMatcher
Instance Method Details
#difference(v) ⇒ Object
725 726 727 |
# File 'lib/scraperwiki-api/matchers.rb', line 725 def difference(v) raise NotImplementerError, 'Subclasses must implement this method' end |
#failure_predicate ⇒ Object
729 730 731 |
# File 'lib/scraperwiki-api/matchers.rb', line 729 def failure_predicate "#{predicate}: #{difference.join ', '}" end |
#match?(v) ⇒ Boolean
708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 |
# File 'lib/scraperwiki-api/matchers.rb', line 708 def match?(v) w = Yajl::Parser.parse v if Hash === w difference(w).empty? elsif Array === w w.all? do |x| if Hash === x difference(x).empty? else raise NotImplementerError, 'Can only handle subfields that are hashes or arrays of hashes' end end else raise NotImplementerError, 'Can only handle subfields that are hashes or arrays of hashes' end end |
#negative_failure_predicate ⇒ Object
733 734 735 |
# File 'lib/scraperwiki-api/matchers.rb', line 733 def negative_failure_predicate "#{negative_predicate}: #{difference.join ', '}" end |