Class: UrlToContents::Url
- Inherits:
-
Object
- Object
- UrlToContents::Url
- Includes:
- Site
- Defined in:
- lib/url_to_contents/url.rb
Constant Summary
Constants included from Site
Site::Tudou, Site::Weibo, Site::Youku
Instance Attribute Summary collapse
-
#doc ⇒ Object
Returns the value of attribute doc.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize(url) ⇒ Url
constructor
A new instance of Url.
- #parse ⇒ Object
- #prepared_url(url) ⇒ Object
- #which_site?(url = @url) ⇒ Boolean
Constructor Details
#initialize(url) ⇒ Url
Returns a new instance of Url.
11 12 13 14 |
# File 'lib/url_to_contents/url.rb', line 11 def initialize(url) @url = prepared_url(url) @doc = Nokogiri::HTML(open(@url)) end |
Instance Attribute Details
#doc ⇒ Object
Returns the value of attribute doc.
9 10 11 |
# File 'lib/url_to_contents/url.rb', line 9 def doc @doc end |
#url ⇒ Object
Returns the value of attribute url.
9 10 11 |
# File 'lib/url_to_contents/url.rb', line 9 def url @url end |
Instance Method Details
#parse ⇒ Object
28 29 30 |
# File 'lib/url_to_contents/url.rb', line 28 def parse UrlToContents::Parser.new(@doc).send which_site? end |
#prepared_url(url) ⇒ Object
16 17 18 19 |
# File 'lib/url_to_contents/url.rb', line 16 def prepared_url(url) return url.sub(/weibo.com/,'weibo.cn') if which_site?(url) == Weibo return url end |
#which_site?(url = @url) ⇒ Boolean
21 22 23 24 25 26 |
# File 'lib/url_to_contents/url.rb', line 21 def which_site?(url = @url) return Youku if url.include?('v.youku.com') return Weibo if (url.include?('weibo.com')|| url.include?('weibo.cn')) return Tudou if url.include?('tudou.com') return Invalid_url end |