Class: UrlFinder::BaseReader

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/url_finder/readers/base_reader.rb

Overview

Base class for reader implementations

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content) ⇒ BaseReader

Initialize reader

Parameters:

  • string (String)

    to find URLs in



18
19
20
21
# File 'lib/url_finder/readers/base_reader.rb', line 18

def initialize(content)
  @content = content
  @urls = nil
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



14
15
16
# File 'lib/url_finder/readers/base_reader.rb', line 14

def content
  @content
end

Class Method Details

.urls(*args) ⇒ BaseReader

Alias for #new

Returns:



8
9
10
# File 'lib/url_finder/readers/base_reader.rb', line 8

def self.urls(*args)
  new(*args)
end

Instance Method Details

#each(&block) ⇒ Object

Yield each url

See Also:

  • Enumerable#each


25
26
27
# File 'lib/url_finder/readers/base_reader.rb', line 25

def each(&block)
  urls.each(&block)
end

#empty?true, false

Returns true if no URLs were found

Returns:

  • (true, false)

    true if no URLs were found



36
37
38
# File 'lib/url_finder/readers/base_reader.rb', line 36

def empty?
  urls.empty?
end

#to_aArray<String>

Returns the URLs as an array

Returns:

  • (Array<String>)

    the found URLs



42
43
44
# File 'lib/url_finder/readers/base_reader.rb', line 42

def to_a
  urls
end

#urlsObject

Raises:

  • (NotImplementedError)

    raises since this should be implemented in subclass



30
31
32
# File 'lib/url_finder/readers/base_reader.rb', line 30

def urls
  raise(NotImplementedError, 'subclass must implement!')
end