Created
November 11, 2015 02:37
-
-
Save inakagawa/09a92512366875987ad6 to your computer and use it in GitHub Desktop.
rubyの練習
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "date" | |
require "optparse" | |
class DateWeek | |
@@wday_ja = ['日','月','火','水','木','金','土'] | |
def initialize | |
@today = Date.today | |
@this_monday = @today - (@today.cwday - 1) | |
@this_friday = @this_monday + 4 | |
end | |
def cal_this_week | |
@this_monday.upto(@this_friday) do |date| | |
puts '## ' + dateformat(date) | |
end | |
end | |
def weekno_date | |
puts "Wk#{@this_monday.cweek}: #{dateformat(@this_monday)} - #{dateformat(@this_friday)}" | |
end | |
private | |
def dateformat(date, opt=nil) | |
retstr = sprintf("%2d/%2d (%s)" , date.mon, date.day, @@wday_ja[date.wday]) | |
return retstr | |
end | |
end | |
dw = DateWeek.new | |
opt = OptionParser.new | |
# 登録するだけ | |
opt.on('-w'){dw.weekno_date()} | |
opt.on('-c'){dw.cal_this_week()} | |
# parseして処理実行 | |
opt.parse(ARGV) |
Author
inakagawa
commented
Nov 11, 2015
- 日付の演算
- OptionParser
- on() で処理を登録して、parse()で実行 (処理順はどうなる?)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment