Class: Misawa
- Inherits:
-
Object
- Object
- Misawa
- Defined in:
- lib/version.rb,
lib/Ruby4Misawa.rb
Defined Under Namespace
Classes: NotFoundError
Constant Summary collapse
- VERSION =
'0.1.4'
- DOMAIN =
'http://jigokuno.com/'
- @@categories =
{}
Instance Method Summary collapse
-
#initialize(name, page = 0) ⇒ Misawa
constructor
A new instance of Misawa.
- #scrape ⇒ Object
Constructor Details
#initialize(name, page = 0) ⇒ Misawa
Returns a new instance of Misawa.
21 22 23 24 25 |
# File 'lib/Ruby4Misawa.rb', line 21 def initialize(name, page = 0) @name = name @cid = @name.is_a?(Integer) ? @name : name_to_cid(@name) @page = page end |
Instance Method Details
#scrape ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/Ruby4Misawa.rb', line 27 def scrape data = [] begin nokogiri = Nokogiri.HTML(open(misawa_uri).read) rescue OpenURI::HTTPError raise NotFoundError end # parse some attributes nokogiri.xpath('//comment()[contains(., "rdf")]').each do |entry| attributes = Nokogiri.XML(entry.to_s.toutf8.gsub(/^<!--|-->$/, "")).child.css('rdf|Description')[0].attributes data << %w[title date identifier].inject({}) do |result, key| result[key.to_sym] = attributes[key].value result end end # parse images nokogiri.css('img.pict').to_a.each_with_index { |image, i| data[i].merge!(:image => image['src'], :body => image['alt']) } data end |