Class: ScraperWiki::API::Matchers::DatastoreMatcher

Inherits:
CustomMatcher
  • Object
show all
Defined in:
lib/scraperwiki-api/matchers.rb

Overview

Datastore matchers —————————————————–

Direct Known Subclasses

FieldMatcher, SetAnyOf

Instance Method Summary collapse

Methods inherited from CustomMatcher

#initialize

Constructor Details

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

Instance Method Details

#does_not_match?(actual) ⇒ Boolean

Returns:

  • (Boolean)


383
384
385
386
387
# File 'lib/scraperwiki-api/matchers.rb', line 383

def does_not_match?(actual)
  super
  @matches = matches
  @matches.empty?
end

#failure_descriptionObject

Raises:

  • (NotImplementerError)


421
422
423
# File 'lib/scraperwiki-api/matchers.rb', line 421

def failure_description
  raise NotImplementerError, 'Subclasses must implement this method'
end

#failure_messageObject



413
414
415
# File 'lib/scraperwiki-api/matchers.rb', line 413

def failure_message
  "#{failure_size} of #{items.size} #{failure_description}\n#{failures.map(&:inspect).join "\n"}"
end

#failure_sizeObject



405
406
407
408
409
410
411
# File 'lib/scraperwiki-api/matchers.rb', line 405

def failure_size
  if @mismatches
    @mismatches.size
  else
    @matches.size
  end
end

#failuresObject



397
398
399
400
401
402
403
# File 'lib/scraperwiki-api/matchers.rb', line 397

def failures
  if @mismatches
    @mismatches
  else
    @matches
  end
end

#itemsObject



361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
# File 'lib/scraperwiki-api/matchers.rb', line 361

def items
  @items ||= if Array === @actual
    @actual
  elsif Hash === @actual
    @actual['data'].map do |array|
      hash = {}
      @actual['keys'].each_with_index do |key,index|
        hash[key] = array[index]
      end
      hash
    end
  else
    raise NotImplementerError, "Can only handle jsondict or jsonlist formats"
  end
end

#matchesObject

Raises:

  • (NotImplementerError)


389
390
391
# File 'lib/scraperwiki-api/matchers.rb', line 389

def matches
  raise NotImplementerError, 'Subclasses must implement this method'
end

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


377
378
379
380
381
# File 'lib/scraperwiki-api/matchers.rb', line 377

def matches?(actual)
  super
  @mismatches = mismatches
  @mismatches.empty?
end

#mismatchesObject

Raises:

  • (NotImplementerError)


393
394
395
# File 'lib/scraperwiki-api/matchers.rb', line 393

def mismatches
  raise NotImplementerError, 'Subclasses must implement this method'
end

#negative_failure_descriptionObject

Raises:

  • (NotImplementerError)


425
426
427
# File 'lib/scraperwiki-api/matchers.rb', line 425

def negative_failure_description
  raise NotImplementerError, 'Subclasses must implement this method'
end

#negative_failure_messageObject



417
418
419
# File 'lib/scraperwiki-api/matchers.rb', line 417

def negative_failure_message
  "#{failure_size} of #{items.size} #{negative_failure_description}\n#{failures.map(&:inspect).join "\n"}"
end