Last active
December 27, 2015 00:59
-
-
Save urfolomeus/7241845 to your computer and use it in GitHub Desktop.
NaNoWriMo helper script. Gives you a quick summary of progress so far.
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
#!/usr/bin/env ruby | |
class NaNoBot | |
TARGET_WORDS = 50000 | |
TOTAL_DAYS = 30 | |
WELL_DONE = [ | |
"Get in!", | |
"Doing great!", | |
"Nice job!", | |
"Keep it up!" | |
] | |
PEP_TALK = [ | |
"You can do it!", | |
"It's not too late to catch up!", | |
"A bit of extra effort will get you passed the slump!", | |
"Ach well, it's only for fun ;)" | |
] | |
attr_reader :word_count | |
def initialize(file_name) | |
@word_count = calc_word_count(file_name) | |
end | |
def words_to_go | |
TARGET_WORDS - word_count | |
end | |
def avg_per_day | |
word_count / days_in | |
end | |
def avg_to_complete | |
return words_to_go unless days_to_go > 0 | |
words_to_go / days_to_go | |
end | |
def random_platitude | |
if word_count < target_word_count | |
PEP_TALK.sample | |
else | |
WELL_DONE.sample | |
end | |
end | |
private | |
def calc_word_count(file_name) | |
File.open(file_name) do |f| | |
f.each_line.inject(0) {|count, line| count += line.scan(/\w+/).count } | |
end | |
end | |
def days_in | |
Time.now.mday | |
end | |
def days_to_go | |
TOTAL_DAYS - days_in | |
end | |
def target_word_count | |
days_in * target_wpd | |
end | |
def target_wpd | |
TARGET_WORDS / TOTAL_DAYS | |
end | |
end | |
nanobot = NaNoBot.new(ARGV.shift) | |
puts "So far: #{nanobot.word_count}" | |
puts "To go: #{nanobot.words_to_go}" | |
puts "WPD so far: #{nanobot.avg_per_day}" | |
puts "WPD req'd to complete: #{nanobot.avg_to_complete}" | |
puts | |
puts nanobot.random_platitude |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment