Class: Aranha::Parsers::SourceAddress

Inherits:
Object
  • Object
show all
Defined in:
lib/aranha/parsers/source_address.rb,
lib/aranha/parsers/source_address/base.rb,
lib/aranha/parsers/source_address/file.rb,
lib/aranha/parsers/source_address/http_get.rb,
lib/aranha/parsers/source_address/hash_http_get.rb,
lib/aranha/parsers/source_address/hash_http_base.rb,
lib/aranha/parsers/source_address/hash_http_post.rb,
lib/aranha/parsers/source_address/fetch_content_error.rb,
lib/aranha/parsers/source_address/hash_http_base/headers.rb

Defined Under Namespace

Classes: Base, FetchContentError, File, HashHttpBase, HashHttpGet, HashHttpPost, HttpGet

Constant Summary collapse

SUBS =
[
  ::Aranha::Parsers::SourceAddress::HashHttpGet,
  ::Aranha::Parsers::SourceAddress::HashHttpPost,
  ::Aranha::Parsers::SourceAddress::HttpGet,
  ::Aranha::Parsers::SourceAddress::File
].freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.deserialize(string) ⇒ Object



31
32
33
# File 'lib/aranha/parsers/source_address.rb', line 31

def deserialize(string)
  new(string =~ %r{\A[a-z]+://} ? string.strip : ::YAML.load(string)) # rubocop:disable Security/YAMLLoad
end

.detect_sub(source) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/aranha/parsers/source_address.rb', line 20

def detect_sub(source)
  return source.sub if source.is_a?(self)

  SUBS.each do |sub_class|
    sub_class.new(source).then do |sub|
      return sub if sub.valid?
    end
  end
  raise "No content fetcher found for source \"#{source}\""
end

.from_file(path) ⇒ Object



35
36
37
# File 'lib/aranha/parsers/source_address.rb', line 35

def from_file(path)
  deserialize(::File.read(path))
end

Instance Method Details

#serializeObject



48
49
50
# File 'lib/aranha/parsers/source_address.rb', line 48

def serialize
  "#{sub.serialize.strip}\n"
end

#to_sObject



44
45
46
# File 'lib/aranha/parsers/source_address.rb', line 44

def to_s
  sub.url
end