Last active
December 17, 2015 09:49
-
-
Save mtsmfm/5590590 to your computer and use it in GitHub Desktop.
にっぽーさくせー
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
#coding:utf-8 | |
require 'fileutils' | |
task :default => :create_todays_report | |
desc "create today's almost daily report" | |
task :create_todays_report do | |
report = Report.new | |
report.create_dir | |
report.create_file | |
end | |
desc "commit" | |
task :commit do | |
commit_message = "Publish 日刊mtsmfm #{Report.new.date_str}" | |
`git commit -m '#{commit_message}'` | |
end | |
class Report | |
def initialize | |
@now = Time.now | |
end | |
def date_str | |
@now.strftime("%Y-%m-%d") | |
end | |
def dir_path | |
month = @now.strftime("%b").downcase | |
week_num = %w[0 1st 2nd 3rd 4th 5th][@now.week_num_of_month] | |
"#{month}/#{week_num}_week" | |
end | |
def file_path | |
"#{dir_path}/#{date_str}.md" | |
end | |
def create_dir | |
if Dir::exists?(dir_path) | |
puts "Dir #{dir_path} already exists" | |
else | |
puts "creating #{dir_path}..." | |
FileUtils.mkdir_p(dir_path) | |
end | |
end | |
def create_file | |
if File::exists?(file_path) | |
puts "File #{file_path} already exists" | |
else | |
puts "creating #{file_path}..." | |
open(file_path, 'w') do |f| | |
f.puts template | |
end | |
end | |
end | |
def template | |
return <<-EOS | |
# #{date_str} | |
## やったこと | |
## きぶん | |
EOS | |
end | |
end | |
class Time | |
def week_num_of_month | |
date = self | |
wday = (date.wday == 0) ? 6 : date.wday - 1 | |
(date.day - wday + 13) / 7 | |
end | |
end |
FileUtils.mkdir_p('hoge/huga/')
たしか、これなら”なければつくる”だから if
がけせそう
コメントながすからだめか
@hrysd thx!
file と dir を同じような書きかたをすることで
のちにリファクタしたいなーという意図があります。
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
close
がないほうがかっこいいと思います。