Class: Gaba

Inherits:
Object
  • Object
show all
Defined in:
lib/gaba.rb,
lib/gaba/version.rb

Constant Summary collapse

VERSION =
"0.0.1"

Instance Method Summary collapse

Instance Method Details

#startObject



4
5
6
7
8
9
10
11
# File 'lib/gaba.rb', line 4

def start
  to_hash.each do |topic|
    date = topic[:date]
    url = topic[:url]
    title = topic[:title]
    puts "#{date} #{title} #{url}"
  end
end

#to_hashObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/gaba.rb', line 13

def to_hash
  require 'nokogiri'
  require 'open-uri'
  website = 'http://www.gaba-2000.com/'
  doc = Nokogiri::HTML(open(website))
  doc.css('#topix dl').map do |elem|
    path = elem.css('dd a').attr('href').to_s
    require 'uri'
    require 'cgi'
    article_id = CGI.parse(URI.parse(path).query)["q"].first.to_i
    {
     artcile_id: article_id,
     url: website + path,
     date: elem.css('dt').text,
     title: elem.css('dd').text.gsub(/[\r\n]+/,"|")
    }
  end
end

#to_jsonObject



32
33
34
35
# File 'lib/gaba.rb', line 32

def to_json
  require 'json'
  to_hash.to_json
end