Skip to content

Instantly share code, notes, and snippets.

@mtsmfm
Last active December 17, 2015 09:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mtsmfm/5590590 to your computer and use it in GitHub Desktop.
Save mtsmfm/5590590 to your computer and use it in GitHub Desktop.
にっぽーさくせー
#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
@hrysd
Copy link

hrysd commented May 16, 2013

close がないほうがかっこいいと思います。

open(file_name, 'w') do |f|
  f.puts content
end

@hrysd
Copy link

hrysd commented May 16, 2013

FileUtils.mkdir_p('hoge/huga/')

たしか、これなら”なければつくる”だから if がけせそう

@hrysd
Copy link

hrysd commented May 16, 2013

コメントながすからだめか

@mtsmfm
Copy link
Author

mtsmfm commented May 17, 2013

@hrysd thx!

file と dir を同じような書きかたをすることで
のちにリファクタしたいなーという意図があります。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment