Class: KanpouWatcher::Kanpou
- Inherits:
-
Object
- Object
- KanpouWatcher::Kanpou
- Defined in:
- lib/kanpou-watcher.rb
Instance Attribute Summary collapse
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
-
#initialize(uri, label) ⇒ Kanpou
constructor
- uri
- Kanpou uri label
-
Kanpou label name.
-
#pdf ⇒ Object
Returns Kanpou pdf uris.
Constructor Details
#initialize(uri, label) ⇒ Kanpou
- uri
-
Kanpou uri
- label
-
Kanpou label name
12 13 14 15 16 17 |
# File 'lib/kanpou-watcher.rb', line 12 def initialize(uri, label) @label = label @uri = uri year, month, day = /(20\d{2})(\d{2})(\d{2})/.match(uri.to_s)[1..3] @date = Date.new(year.to_i, month.to_i, day.to_i) end |
Instance Attribute Details
#date ⇒ Object (readonly)
Returns the value of attribute date.
8 9 10 |
# File 'lib/kanpou-watcher.rb', line 8 def date @date end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
8 9 10 |
# File 'lib/kanpou-watcher.rb', line 8 def label @label end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
8 9 10 |
# File 'lib/kanpou-watcher.rb', line 8 def uri @uri end |
Instance Method Details
#pdf ⇒ Object
Returns Kanpou pdf uris.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/kanpou-watcher.rb', line 20 def pdf begin if /0f.html$/.match(@uri.to_s) uri = URI.parse(@uri.to_s.gsub("f.html", ".html")) list = Array.new (Hpricot(uri.read)/"a").each do |link| list << uri + "./pdf/" + link[:href].gsub("f.html", ".pdf") end return list.uniq else path = @uri.path.split("/") uri = @uri.clone uri.path = (path[0..-2] << "pdf" << path[-1].gsub("f.html", ".pdf")).join("/") return [uri] end rescue OpenURI::HTTPError p @uri end end |