Class: WWW::VideoScraper::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/www/video_scraper/base.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, opt = nil) ⇒ Base

Returns a new instance of Base.

Raises:

  • (StandardError)


32
33
34
35
36
37
38
39
40
# File 'lib/www/video_scraper/base.rb', line 32

def initialize(url, opt = nil)
  @page_url = url
  @opt = (opt || {})
  url_regex = self.class.instance_variable_get(:@url_regex)
  Array(url_regex).any? do |r|
    @url_regex_match = r.match(@page_url).freeze
  end
  raise StandardError, "url is not #{self.class.name} link: #{url}" if @url_regex_match.nil?
end

Instance Attribute Details

#embed_tagObject (readonly)

Returns the value of attribute embed_tag.



13
14
15
# File 'lib/www/video_scraper/base.rb', line 13

def embed_tag
  @embed_tag
end

#page_urlObject (readonly)

Returns the value of attribute page_url.



13
14
15
# File 'lib/www/video_scraper/base.rb', line 13

def page_url
  @page_url
end

#thumb_urlObject (readonly)

Returns the value of attribute thumb_url.



13
14
15
# File 'lib/www/video_scraper/base.rb', line 13

def thumb_url
  @thumb_url
end

#titleObject (readonly)

Returns the value of attribute title.



13
14
15
# File 'lib/www/video_scraper/base.rb', line 13

def title
  @title
end

#video_urlObject (readonly)

Returns the value of attribute video_url.



13
14
15
# File 'lib/www/video_scraper/base.rb', line 13

def video_url
  @video_url
end

Class Method Details

.scrape(url, opt = nil) ⇒ Object



25
26
27
28
29
# File 'lib/www/video_scraper/base.rb', line 25

def scrape(url, opt = nil)
  instance = self.new(url, opt)
  instance.scrape
  instance
end

.url_regex(regex) ⇒ Object



17
18
19
# File 'lib/www/video_scraper/base.rb', line 17

def url_regex(regex)
  @url_regex = regex
end

.valid_url?(url) ⇒ Boolean



21
22
23
# File 'lib/www/video_scraper/base.rb', line 21

def valid_url?(url)
  Array(@url_regex).any? { |r| r.match(url) }
end

Instance Method Details

#scrapeObject

Raises:

  • (StandardError)


42
43
44
# File 'lib/www/video_scraper/base.rb', line 42

def scrape
  raise StandardError, 'not implemented yet'
end