Class: Retriever::Target

Inherits:
Object
  • Object
show all
Defined in:
lib/retriever/target.rb

Constant Summary collapse

HTTP_RE =
Regexp.new(/^http/i).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, file_re = nil) ⇒ Target

Returns a new instance of Target.



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/retriever/target.rb', line 11

def initialize(url, file_re = nil)
  fail 'Bad URL' unless url.include?('.')
  url         = "http://#{url}" unless HTTP_RE =~ url
  target_uri  = Addressable::URI.parse(Addressable::URI.encode(url))
  @target     = target_uri.to_s
  @host       = target_uri.host
  @host_re    = Regexp.new(@host.sub('www.', ''))
  @file_re  ||= file_re
  @scheme     = target_uri.scheme
  @port       = target_uri.port
end

Instance Attribute Details

#file_reObject (readonly)

Returns the value of attribute file_re.



9
10
11
# File 'lib/retriever/target.rb', line 9

def file_re
  @file_re
end

#hostObject (readonly)

Returns the value of attribute host.



9
10
11
# File 'lib/retriever/target.rb', line 9

def host
  @host
end

#host_reObject (readonly)

Returns the value of attribute host_re.



9
10
11
# File 'lib/retriever/target.rb', line 9

def host_re
  @host_re
end

#portObject (readonly)

Returns the value of attribute port.



9
10
11
# File 'lib/retriever/target.rb', line 9

def port
  @port
end

#schemeObject (readonly)

Returns the value of attribute scheme.



9
10
11
# File 'lib/retriever/target.rb', line 9

def scheme
  @scheme
end

#sourceObject (readonly)

Returns the value of attribute source.



9
10
11
# File 'lib/retriever/target.rb', line 9

def source
  @source
end

#targetObject (readonly)

Returns the value of attribute target.



9
10
11
# File 'lib/retriever/target.rb', line 9

def target
  @target
end

Instance Method Details

#resync_target_and_return_source(url) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/retriever/target.rb', line 39

def resync_target_and_return_source(url)
  new_t   = Retriever::Target.new(url)
  @target = new_t.target
  @host   = new_t.host
  @scheme = new_t.scheme
  new_t.source
end