Class: RSSParser
- Inherits:
-
Object
- Object
- RSSParser
- Defined in:
- lib/rrs_parser.rb
Instance Attribute Summary collapse
-
#download_link ⇒ Object
readonly
Returns the value of attribute download_link.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#form_action ⇒ Object
readonly
Returns the value of attribute form_action.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#page ⇒ Object
readonly
Returns the value of attribute page.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize(url) ⇒ RSSParser
constructor
A new instance of RSSParser.
- #parse_next_page ⇒ Object
Constructor Details
#initialize(url) ⇒ RSSParser
Returns a new instance of RSSParser.
3 4 5 6 7 8 9 10 |
# File 'lib/rrs_parser.rb', line 3 def initialize(url) @page = Hpricot(Net::HTTP.get(URI.parse(url))) @url = url @download_link = "" @filename = "" find_form_action end |
Instance Attribute Details
#download_link ⇒ Object (readonly)
Returns the value of attribute download_link.
2 3 4 |
# File 'lib/rrs_parser.rb', line 2 def download_link @download_link end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
2 3 4 |
# File 'lib/rrs_parser.rb', line 2 def filename @filename end |
#form_action ⇒ Object (readonly)
Returns the value of attribute form_action.
2 3 4 |
# File 'lib/rrs_parser.rb', line 2 def form_action @form_action end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
2 3 4 |
# File 'lib/rrs_parser.rb', line 2 def @metadata end |
#page ⇒ Object (readonly)
Returns the value of attribute page.
2 3 4 |
# File 'lib/rrs_parser.rb', line 2 def page @page end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
2 3 4 |
# File 'lib/rrs_parser.rb', line 2 def url @url end |
Instance Method Details
#parse_next_page ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rrs_parser.rb', line 12 def parse_next_page @metadata = {} resp = Net::HTTP.post_form(URI.parse(@form_action), {"dl.start"=>"free"}) body = resp.body body.each_line do |line| if line =~ /.*name="dlf"\saction="(\S*)"/ $stderr.puts "-> Downloading #{$1}..." @download_link = $1 @filename = $1.to_s.split("/").last end if line =~ /var\s*c\s*=\s*(\d+)/ @metadata[:seconds] = $1.to_i elsif line =~ /try\s*again\s*in\s*about\s*(\d+)\s*minutes/ @metadata[:minutes] = $1.to_i end end @metadata end |