Skip to content

Instantly share code, notes, and snippets.

@tobynet
Created August 29, 2012 08:46
Show Gist options
  • Save tobynet/3508699 to your computer and use it in GitHub Desktop.
Save tobynet/3508699 to your computer and use it in GitHub Desktop.
erokimos text-converter CLI
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
program = File.basename($PROGRAM_NAME)
USAGE = <<EOD
usage: #{program} text
example:
$ #{program} "みんなでワイワイ バーベキューなう"
たわわに実るみんなでワイワイ 甘美なバーベキューなう
or
$ echo "みんなでワイワイ バーベキューなう" | #{program}
ピンク色のみんなでワイワイ 柔らかなバーベキューなう
EOD
API_URI="http://erokimos.jgate.de"
require 'net/http'
if $stdin.tty? && ARGV.empty?
puts USAGE
else
text = ARGV.shift || ARGF.read #|| "みんなでワイワイ バーベキューなう"
puts Net::HTTP.get(URI(URI.encode("#{API_URI}/convert?q=#{text}")))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment