Skip to content

Commit

Permalink
* sample/biorhythm.rb: follow Ruby 1.9 libraries.
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14636 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
gotoyuzo committed Dec 24, 2007
1 parent a79ce52 commit a560576
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 75 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Tue Dec 25 06:19:04 2007 GOTOU Yuuzou <[email protected]>

* sample/biorhythm.rb: follow Ruby 1.9 libraries.

Tue Dec 25 06:15:01 2007 Koichi Sasada <[email protected]>

* vm.c: add dummy toplevel frame.
Expand Down
115 changes: 40 additions & 75 deletions sample/biorhythm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,8 @@

include Math
require "date.rb"
require "parsearg.rb"
require "parsedate.rb"

def usage()
print "Usage:\n"
print "biorhythm.rb [options]\n"
print " options...\n"
print " -D YYYYMMDD(birthday) : use default values.\n"
print " --sdate | --date YYYYMMDD : use system date; use specified date.\n"
print " --birthday YYYYMMDD : specifies your birthday.\n"
print " -v | -g : show values or graph.\n"
print " --days DAYS : graph range (only in effect for graphs).\n"
print " --help : help\n"
end
$USAGE = 'usage'
require "optparse"
require "optparse/date"

def printHeader(y, m, d, p, w)
print "\n>>> Biorhythm <<<\n"
Expand All @@ -58,60 +45,52 @@ def getPosition(z)
return phys, emot, geist
end

def parsedate(s)
ParseDate::parsedate(s).values_at(0, 1, 2)
end

def name_of_week(date)
Date::DAYNAMES[date.wday]
def prompt(msg)
$stderr.print msg
return gets.chomp
end

#
# main program
#
parseArgs(0, nil, "vg", "D:", "sdate", "date:", "birthday:", "days:")

if $OPT_D
dd = Date.today
bd = Date.new(*parsedate($OPT_D))
ausgabeart = "g"
else
if $OPT_birthday
bd = Date.new(*parsedate($OPT_birthday))
else
STDERR.print("Birthday (YYYYMMDD) : ")
unless (si = STDIN.gets.chop).empty?
bd = Date.new(*parsedate(si))
end
end
if !bd
STDERR.print "BAD Input Birthday!!\n"
exit()
options = {
:graph => true,
:date => Date.today,
:days => 9,
}
ARGV.options do |opts|
opts.on("-b", "--birthday=DATE", Date, "specify your birthday"){|v|
options[:birthday] = v
}
opts.on("--date=DATE", Date, "specify date to show"){|v|
options[:date] = v
}
opts.on("-g", "--show-graph", TrueClass, "show graph (default)"){|v|
options[:graph] = v
}
opts.on("-v", "--show-values", TrueClass, "show values"){|v|
options[:graph] = !v
}
opts.on("--days=DAYS", Integer, "graph range (only in effect for graph)"){|v|
options[:days] = v - 1
}
opts.on_tail("-h", "--help", "show this message"){puts opts; exit}
begin
opts.parse!
rescue => ex
puts "Error: #{ex.message}"
puts opts
exit
end
end

if $OPT_sdate
dd = Date.today
elsif $OPT_date
dd = Date.new(*parsedate($OPT_date))
else
STDERR.print("Date [<RETURN> for Systemdate] (YYYYMMDD) : ")
unless (si = STDIN.gets.chop).empty?
dd = Date.new(*parsedate(si))
end
end
dd ||= Date.today
bd = options[:birthday] || Date.parse(prompt("Your birthday (YYYYMMDD): "))
dd = options[:date] || Date.today
ausgabeart = options[:graph] ? "g" : "v"
display_period = options[:days]

if $OPT_v
ausgabeart = "v"
elsif $OPT_g
ausgabeart = "g"
else
STDERR.print("Values for today or Graph (v/g) [default g] : ")
ausgabeart = STDIN.gets.chop
end
end
if ausgabeart == "v"
printHeader(bd.year, bd.month, bd.day, dd - bd, name_of_week(bd))
printHeader(bd.year, bd.month, bd.day, dd - bd, bd.strftime("%a"))
print "\n"

phys, emot, geist = getPosition(dd - bd)
Expand All @@ -121,21 +100,7 @@ def name_of_week(date)
printf "Mental: %d%%\n", geist
print "\n"
else
if $OPT_days
display_period = $OPT_days.to_i
elsif $OPT_D
display_period = 9
else
STDERR.printf("Graph for how many days [default 10] : ")
display_period = STDIN.gets.chop
if display_period.empty?
display_period = 9
else
display_period = display_period.to_i - 1
end
end

printHeader(bd.year, bd.month, bd.day, dd - bd, name_of_week(bd))
printHeader(bd.year, bd.month, bd.day, dd - bd, bd.strftime("%a"))
print " P=physical, E=emotional, M=mental\n"
print " -------------------------+-------------------------\n"
print " Bad Condition | Good Condition\n"
Expand Down

0 comments on commit a560576

Please sign in to comment.