Module: Simple2ch

Defined in:
lib/ruby2ch.rb,
lib/ruby2ch/dat.rb,
lib/ruby2ch/res.rb,
lib/ruby2ch/thre.rb,
lib/ruby2ch/board.rb,
lib/ruby2ch/version.rb,
lib/ruby2ch/simple2ch_exception.rb

Defined Under Namespace

Classes: Board, Dat, DatParseException, KakoLogException, NotA2chUrlException, Res, Simple2chException, Thre

Constant Summary

DEBUG =
true
VERSION =
"0.0.1"

Class Method Summary (collapse)

Class Method Details

+ (String) fetch(url)

HTTPでGETする

Parameters:

  • url (URI)

    URL

Returns:

  • (String)

    取得本文



21
22
23
24
25
26
27
# File 'lib/ruby2ch.rb', line 21

def self.fetch(url)
  req = Net::HTTP::Get.new(url.path)
  res = Net::HTTP.start(url.host, url.port) {|http|
    http.request(req)
  }
  res.body.force_encoding("cp932").encode!('utf-8', :undef => :replace)
end

+ (Object) root



14
15
16
# File 'lib/ruby2ch.rb', line 14

def self.root
  File.dirname __dir__
end