Sha256: 0d73e2e9dd30ee16bc6d527b9779d36a9cad803713480e324a2063cf012b0a89

Contents?: true

Size: 713 Bytes

Versions: 3

Compression:

Stored size: 713 Bytes

Contents

module Nutrella
  #
  # Knows how to take the supplied board name and resolve it to a Trello board url.
  #
  class BoardNameResolver
    def initialize(url_cache, search_specification)
      @url_cache = url_cache
      @search_specification = search_specification
    end

    def resolve(board_name, &block)
      matching_url(board_name) || cached_url(board_name, &block)
    end

    private

    def matching_url(board_name)
      return nil unless @search_specification.match?(board_name)

      search_reg_exp = Regexp.new(board_name, Regexp::IGNORECASE)

      @url_cache.search(search_reg_exp)
    end

    def cached_url(board_name, &block)
      @url_cache.fetch(board_name, &block)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
nutrella-1.7.1 lib/nutrella/board_name_resolver.rb
nutrella-1.7.0 lib/nutrella/board_name_resolver.rb
nutrella-1.6.0 lib/nutrella/board_name_resolver.rb