4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

サンシャイン池崎ゲームリゾルバを作ってみた。

Last updated at Posted at 2017-10-18

TL;DR

ここで稼働しています。
https://www.saiuma.com/sunshine

最近、サンシャイン池崎ゲームなるものが考案されたらしい。

ゲームが出来たらリゾルバが欲しくなるのはエンジニアの性ですので、さくっと作りましょう。

コード解説

コード全体はGithubに置いてあります。
https://github.com/nak1114/docker-sinatra-sunshine

さくっと作るため通いなれたsinatraで作りました。
RDBが無いのでRailsはお休みです。
日本語の読みかたを知るためMecabを使っています。
Mecab-Ruby間はnatto gemを使わせてもらいました。

それぞれのインストールは Dockerfile に書いてあります。

コードの肝は以下の部分です。
改行コードなどを除いて"い"と読める単語があったら全てカタカナに直して、最後に一括で"イェー!"に変換です。うん単純だ。
ちなみに@refescapeはTweeter投稿用のパラメータです。

app.rb
  post '/sunshine' do
    text=params[:text]
    ret=""
    nm = Natto::MeCab.new
    text.each_line do |line|
      nm.parse(line.chomp) do |n|
        sp=n.feature.split(",")[7]
        if sp && sp.include?("イ")
          ret+=sp
        else
          ret+=n.surface
        end
      end
      ret+="\n"
    end

    @title="サンシャイン池崎ゲームリゾルバ(結果)"
    @restext=ret.gsub("イ","イェー!")
    @refescape=URI.encode_www_form({"text"=>@restext})
    slim :sunshine
  end

あとがき

こんなの誰か作るだろうと思っていたけど、くだらなすぎて誰も作っていないみたいだったので速攻で作りました。
MecabとRubyの組み合わせは初めてですが全然簡単でした。先人たちの踏破した道は楽でいいですね。

4
2
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?