Created
January 31, 2012 19:47
-
-
Save marka2g/1712520 to your computer and use it in GitHub Desktop.
need an edge-case type test? simply add a new hash y'all!
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
| describe Note do | |
| describe 'notes with valid time entry' do | |
| [ {text: 't:9h20m', parsed_entry: 33600}, | |
| {text: 't:20m', parsed_entry: 1200}, | |
| {text: 't: 9h', parsed_entry: 32400}, | |
| {text: 't: 20m', parsed_entry: 1200}, | |
| {text: 't: 09h', parsed_entry: 32400}, | |
| {text: 'time: 09h', parsed_entry: 32400}, | |
| {text: 'Time: 20m', parsed_entry: 1200} | |
| ].each do |note| | |
| context "note with #{note[:text]}" do | |
| subject { Note.new(text: note[:text]) } | |
| describe '#time_entry?' do | |
| it { subject.time_entry?.should be_true } | |
| end | |
| describe '#time_entry' do | |
| it { subject.time_entry.should eql(note[:parsed_entry]) } | |
| end | |
| end | |
| end | |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
in note.rb
def time_entry?
text.downcase.start_with?('time:', 't:')
end
def time_entry
if match = text.match(/^(t|time):(\s+)?((?\d+h)?)((?\d+m)?)$/i)
(match[:minute].to_i * 60) + (match[:hour].to_i * 3600)
end
end