class Shindan

Shindan Maker Ruby Library

Constants

URL
VERSION

Public Class Methods

new(shindan_id) click to toggle source
# File lib/shindan.rb, line 12
def initialize(shindan_id)
  @shindan_id = shindan_id
end

Public Instance Methods

get(name) click to toggle source
# File lib/shindan.rb, line 16
def get(name)
  shindan(name).search('div.result').inner_text.strip
end
open(name) click to toggle source
# File lib/shindan.rb, line 20
def open(name)
  system "x-www-browser #{temp_html shindan(name).body}"
end

Private Instance Methods

css() click to toggle source
# File lib/shindan.rb, line 26
def css
  "#{ URL }/css/pc8.css"
end
hatena_haiku() click to toggle source
# File lib/shindan.rb, line 34
def hatena_haiku
  "#{ URL }/img/hatenahaiku.png"
end
mixi_voice() click to toggle source
# File lib/shindan.rb, line 38
def mixi_voice
  "#{ URL }/img/mixivoice.png"
end
rewrite(body) click to toggle source
# File lib/shindan.rb, line 61
def rewrite(body)
  result = body.dup
  result.gsub! %r{/css/pc8\.css}, css
  result.gsub! %r{/img/logo_head\.png}, logo
  result.gsub! %r{/img/mixivoice\.png}, mixi_voice
  result.gsub! %r{/img/hatenahaiku\.png}, hatena_haiku
end
shindan(name) click to toggle source
# File lib/shindan.rb, line 42
def shindan(name)
  agent = Mechanize.new
  agent.get "#{URL}/#{@shindan_id}"
  agent.page.form_with(name: 'enter') do | form |
    form['u'] = name.toutf8
    form.click_button
  end
  agent.page
end
temp_html(body) click to toggle source
# File lib/shindan.rb, line 52
def temp_html(body)
  t = Tempfile.new('shindan')
  t.puts rewrite(body)
  t.close
  html = t.path + '.html'
  FileUtils.mv t.path, html
  html
end