家計簿ソフト

kkb.rb などの名前で保存し、実行してください(% ruby kkb.rb で実行)。

  • ソースの2行目の保存ファイルのパス(/home/masaking/.kkb.csv)は変更してください。
  • でそのファイルは自分で用意しておいてください。% touch ~/.kkb.csv などとすると良いかと。

しかしテキトーなコードですな・・・。


print "\n * 簡単家計簿 *\n 2003.10.30 masaking\n\n"
f = open("/home/masaking/.kkb.csv", "a")

# 日付け入力
day = Time.now
print "日付けは ", day.year, ".", day.month, ".", day.day, " でいいですか?\n"
print "( Y : y[Return], N : ピリオド区切り西暦で入力)\n"
input = STDIN.gets.chop
if input == "y"
curYear = day.year.to_s
curMonth = day.month.to_s
curDay = day.day.to_s
else
tmp = input.split(".")
curYear = tmp[0]
curMonth = tmp[1]
curDay = tmp[2]
end
curDate = curYear + "." + curMonth + "." + curDay
print ">> 現在の日付け : ", curDate, "\n\n"

# 入力
print "( help | f | t | m | r | h | date | exit | q)\n"
print "input > "
while input = STDIN.gets
input.chop!
if input == "help"
print "\"f 値段 備考\"のような書式で入力してください。\n"
print "f は食料品, t は交通費, m は交際費, r は住居・光熱費, h は本や雑誌です。\n\n"
elsif input == "date"
print "現在の日付けは ", curYear, ".", curMonth, ".", curDay, " です。\n"
print "( 変更しない : y[Return], 変更する : ピリオド区切り西暦で入力)\n"
input = STDIN.gets.chop!
if input == "y"
else
tmp = input.split(".")
curYear = tmp[0]
curMonth = tmp[1]
curDay = tmp[2]
end
print ">> 現在の日付け : ", curYear, ".", curMonth, ".", curDay, "\n\n"
curDate = curYear + "." + curMonth + "." + curDay
elsif input == "exit" || input == "q"
f.close
break
else
category = input.split(" ")[0]
price = input.split(" ")[1].to_i
case category
when "f"
print "食料品 ", price, "円\n\n"
f.print curDate, " ", input, "\n"
when "t"
print "交通費 ", price, "円\n\n"
f.print curDate, " ", input, "\n"
when "m"
print "交際費 ", price, "円\n\n"
f.print curDate, " ", input, "\n"
when "r"
print "住居・光熱費 ", price, "円\n\n"
f.print curDate, " ", input, "\n"
when "h"
print "本や雑誌 ", price, "円\n\n"
f.print curDate, " ", input, "\n"
else
print "そのカテゴリはありません。(help, f,t,m,r,h, date, exit,q)\n\n"
end
end
print "input > "
end