Sha256: a216906a397e157b277dfdec0035e00571ed0c63195c0c3ef69d5bf1e5eafb03

Contents?: true

Size: 962 Bytes

Versions: 4

Compression:

Stored size: 962 Bytes

Contents

# frozen_string_literal: true

module UrlFinder
  # Base class for reader implementations
  class BaseReader
    # Alias for #new
    # @return [BaseReader] instance of BaseReader
    def self.urls(*args)
      new(*args)
    end

    include Enumerable

    attr_reader :content

    # Initialize reader
    # @param [String] string to find URLs in
    def initialize(content)
      @content = content
      @urls = nil
    end

    # Yield each url
    # @see Enumerable#each
    def each(&block)
      urls.each(&block)
    end

    # @raise [NotImplementedError] raises since this should be implemented in subclass
    def urls
      raise(NotImplementedError, 'subclass must implement!')
    end

    # Returns true if no URLs were found
    # @return [true, false] true if no URLs were found
    def empty?
      urls.empty?
    end

    # Returns the URLs as an array
    # @return [Array<String>] the found URLs
    def to_a
      urls
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
url_finder-0.2.2 lib/url_finder/readers/base_reader.rb
url_finder-0.2.1 lib/url_finder/readers/base_reader.rb
url_finder-0.2.0 lib/url_finder/readers/base_reader.rb
url_finder-0.1.0 lib/url_finder/readers/base_reader.rb