Sha256: d3fd05417c4582ef3c080dd63439b09bec56eb3e0a0aa3d753f08089f6c1beab

Contents?: true

Size: 828 Bytes

Versions: 2

Compression:

Stored size: 828 Bytes

Contents

require 'thanos/response_holder'
require 'thanos/string_actions'
require 'thanos/api/client'
require 'thanos/factories/character'
require 'thanos/finders/finder_validator'

module Thanos
  class CharacterFinder
    ATTRIBUTES = [:name, :comics, :series, :events, :series,
                  :nameStartsWith, :modifiedSince]

    ATTRIBUTES.each do |attribute|
      parameter = StringActions.parameterize(attribute.to_s)
      define_method("find_by_#{parameter}") do |attr|
        find("#{attribute}".to_sym => attr)
      end
    end

    private

    def find(attribute)
      FinderValidator.validate(attribute, ATTRIBUTES)
      response = Thanos::API::Client.new.get(:characters, attribute)
      results = Thanos::ResponseHolder.new(response).results
      Thanos::Factory::Character.new(results).build
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
thanos-0.6.0 lib/thanos/finders/character_finder.rb
thanos-0.5.0 lib/thanos/finders/character_finder.rb