Class: Aranha::Parsers::SourceAddress::File

Inherits:
HttpGet
  • Object
show all
Defined in:
lib/aranha/parsers/source_address/file.rb

Constant Summary collapse

SCHEME =
'file://'

Instance Attribute Summary

Attributes inherited from HttpGet

#source

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from HttpGet

#==, #final_url, location_uri, #serialize

Constructor Details

#initialize(source) ⇒ File

Returns a new instance of File.



17
18
19
# File 'lib/aranha/parsers/source_address/file.rb', line 17

def initialize(source)
  super source.to_s.gsub(/\A#{Regexp.quote(SCHEME)}/, '')
end

Class Method Details

.valid_source?(source) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/aranha/parsers/source_address/file.rb', line 12

def valid_source?(source)
  source.to_s.start_with?("#{SCHEME}/", '/')
end

Instance Method Details

#contentObject



25
26
27
# File 'lib/aranha/parsers/source_address/file.rb', line 25

def content
  ::File.read(source)
end

#urlObject



21
22
23
# File 'lib/aranha/parsers/source_address/file.rb', line 21

def url
  "#{SCHEME}#{source}"
end