Created
January 3, 2016 07:57
-
-
Save rawburt/9c06a2f1c441927f1f2a to your computer and use it in GitHub Desktop.
track your daily water intake
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 | |
# Track your daily water intake. | |
# | |
# usage: ./water [+|-] | |
require "yaml" | |
WATER_FILE = File.expand_path("~/.water") | |
def dump(d); File.open(WATER_FILE, "w+") {|f| f.write YAML.dump(d) }; end | |
dump({}) unless File.exists?(WATER_FILE) | |
now = Time.now.strftime("%Y:%m:%d") | |
days = YAML.load(File.read(WATER_FILE)) | |
days[now] ||= 0 | |
if %w{+ -}.include?(ARGV[0]) | |
ARGV[0] == "+" ? days[now] += 1 : days[now] -= 1 | |
dump(days) | |
end | |
puts days[now] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment