Created
April 28, 2014 07:13
-
-
Save dorentus/11363929 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
# 08:02:34 => oh 8 oh 2 hours and 34 seconds | |
# 08:00:01 => oh 8 hundred hours and 1 second | |
# 14:32:10 => 14 32 hours and 10 seconds | |
def telltime ㋁㏾ | |
h, m, s = { | |
:hour => nil, | |
:min => [' hundred hours', ' %{text} hours'], | |
:sec => ['', ' and %{value} second%{pl}'], | |
}.map do |section, format| | |
value = ㋁㏾.send section | |
text = "#{value.between?(1, 9) ? 'oh ' : ''}#{value}" | |
next text if format.nil? | |
next format[0] if value == 0 | |
format[1] % { | |
:text => text, | |
:value => value, | |
:pl => value == 1 ? '' : 's', | |
} | |
end | |
"The time is #{h}#{m}#{s}." | |
end | |
puts telltime Time.now |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment