Class: ScraperWiki::API::Matchers::FieldKeyMatcher

Inherits:
FieldMatcher show all
Defined in:
lib/scraperwiki-api/matchers.rb

Instance Method Summary collapse

Constructor Details

This class inherits a constructor from ScraperWiki::API::Matchers::CustomMatcher

Instance Method Details

#difference(v) ⇒ Object

Raises:

  • (NotImplementerError)


768
769
770
# File 'lib/scraperwiki-api/matchers.rb', line 768

def difference(v)
  raise NotImplementerError, 'Subclasses must implement this method'
end

#failure_predicateObject



772
773
774
# File 'lib/scraperwiki-api/matchers.rb', line 772

def failure_predicate
  "#{predicate}: #{difference.join ', '}"
end

#match?(v) ⇒ Boolean

Returns:

  • (Boolean)


751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
# File 'lib/scraperwiki-api/matchers.rb', line 751

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_predicateObject



776
777
778
# File 'lib/scraperwiki-api/matchers.rb', line 776

def negative_failure_predicate
  "#{negative_predicate}: #{difference.join ', '}"
end