Created
August 13, 2010 14:31
-
-
Save solnic/522968 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
| module DataMapper | |
| class Property | |
| class JustTime < Integer | |
| primitive ::String | |
| def dump(val) | |
| case val | |
| when String | |
| h,m = val.split(':').map &:to_i | |
| h % 24 * 60 + m % 60 | |
| else val | |
| end if val.present? | |
| end | |
| def load(val) | |
| if val.present? | |
| h = val / 60 | |
| m = val - h * 60 | |
| "#{h}:#{m}" | |
| end | |
| end | |
| def parse(val) | |
| case val | |
| when Integer then load(val) | |
| else val | |
| end if val.present? | |
| end | |
| def typecast_to_primitive(val) | |
| parse(val) | |
| end | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment