Class: Retriever::Target

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

Constant Summary collapse

HTTP_RE =
Regexp.new(/^http/i).freeze
DUB_DUB_DUB_DOT_RE =
Regexp.new(/^www\./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
# File 'lib/retriever/target.rb', line 11

def initialize(url, file_re = nil)
  url = "http://#{url}" unless HTTP_RE =~ url
  fail 'Bad URL' unless /\./ =~ url
  new_uri = URI(url)
  @target = new_uri.to_s
  @host = new_uri.host
  @host_re = Regexp.new(@host.sub('www.', ''))
  @file_re ||= file_re
end

Instance Attribute Details

#file_re ⇒ Object (readonly)

Returns the value of attribute file_re.



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

def file_re
  @file_re
end

#host ⇒ Object (readonly)

Returns the value of attribute host.



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

def host
  @host
end

#host_re ⇒ Object (readonly)

Returns the value of attribute host_re.



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

def host_re
  @host_re
end

#source ⇒ Object (readonly)

Returns the value of attribute source.



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

def source
  @source
end

#target ⇒ Object (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



37
38
39
40
41
42
# File 'lib/retriever/target.rb', line 37

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