Add get_parsers() and get_formats()
This commit is contained in:
parent
58f75fc966
commit
928c4e9be4
4 changed files with 22 additions and 4 deletions
|
@ -1,6 +1,8 @@
|
|||
## 0.4.0 (in-development)
|
||||
|
||||
* Add basic date arithmetic (still needs tests)
|
||||
* Add `get_formats()` and `get_parsers()` to see list of registered formats and
|
||||
parsers.
|
||||
|
||||
## 0.3.0
|
||||
|
||||
|
|
|
@ -240,6 +240,7 @@ be attempted before engaging the `ec_date` parser.
|
|||
able to parse the string, then it should return `undefined`.
|
||||
+ `deregister_parser(Key)` - If you previously registered a parser with the
|
||||
`qdate` server, you can deregister it by its `Key`.
|
||||
+ `get_parsers()` - Get the list of all registered parsers and their keys.
|
||||
|
||||
### Registering and Deregistering Formatters
|
||||
+ `register_format(Key, FormatString)` - Register a formatting string with
|
||||
|
@ -247,6 +248,7 @@ be attempted before engaging the `ec_date` parser.
|
|||
formatting string.
|
||||
+ `deregister_format(Key)` - Deregister the formatting string from the
|
||||
`qdate` server.
|
||||
+ `get_formats()` - Get the list of all registered formats and their keys.
|
||||
|
||||
### About backwards compatibility with `ec_date` and deterministic parsing
|
||||
|
||||
|
|
|
@ -45,9 +45,11 @@
|
|||
register_parser/1,
|
||||
deregister_parser/1,
|
||||
deregister_parsers/0,
|
||||
get_parsers/0,
|
||||
|
||||
register_format/2,
|
||||
deregister_format/1,
|
||||
get_formats/0,
|
||||
|
||||
set_timezone/1,
|
||||
set_timezone/2,
|
||||
|
@ -564,6 +566,9 @@ clear_timezone(Key) ->
|
|||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Register Parsers %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
get_parsers() ->
|
||||
qdate_srv:get_parsers().
|
||||
|
||||
register_parser(Key, Parser) when is_function(Parser,1) ->
|
||||
qdate_srv:register_parser(Key,Parser).
|
||||
|
||||
|
@ -601,6 +606,9 @@ try_parsers(RawDate,[{ParserKey,Parser}|Parsers]) ->
|
|||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Register Formats %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
get_formats() ->
|
||||
qdate_srv:get_formats().
|
||||
|
||||
register_format(Key, Format) ->
|
||||
qdate_srv:register_format(Key, Format).
|
||||
|
||||
|
|
|
@ -33,7 +33,8 @@
|
|||
|
||||
register_format/2,
|
||||
get_format/1,
|
||||
deregister_format/1
|
||||
deregister_format/1,
|
||||
get_formats/0
|
||||
]).
|
||||
|
||||
%% PUBLIC API FUNCTIONS
|
||||
|
@ -72,7 +73,7 @@ deregister_parsers() ->
|
|||
ok = gen_server:call(?SRV,{deregister_parsers}).
|
||||
|
||||
get_parsers() ->
|
||||
gen_server:call(?SRV,{get_parsers}).
|
||||
gen_server:call(?SRV,get_parsers).
|
||||
|
||||
register_format(Key,Format) ->
|
||||
ok = gen_server:call(?SRV,{register_format,Key,Format}).
|
||||
|
@ -83,6 +84,8 @@ get_format(Key) ->
|
|||
deregister_format(Key) ->
|
||||
ok = gen_server:call(?SRV,{deregister_format,Key}).
|
||||
|
||||
get_formats() ->
|
||||
gen_server:call(?SRV, get_formats).
|
||||
|
||||
%% SERVER FUNCTIONS
|
||||
|
||||
|
@ -125,7 +128,7 @@ handle_call({register_parser,Key,Parser},_From,State) ->
|
|||
NewParsers = dict:store(Key, Parser, State#state.parsers),
|
||||
NewState = State#state{parsers=NewParsers},
|
||||
{reply, Key, NewState};
|
||||
handle_call({get_parsers},_From,State) ->
|
||||
handle_call(get_parsers,_From,State) ->
|
||||
Reply = dict:to_list(State#state.parsers),
|
||||
{reply, Reply, State};
|
||||
handle_call({deregister_parser,Key},_From,State) ->
|
||||
|
@ -146,6 +149,9 @@ handle_call({get_format,Key},_From,State) ->
|
|||
{ok, Format} -> Format
|
||||
end,
|
||||
{reply, Reply,State};
|
||||
handle_call(get_formats,_From,State) ->
|
||||
Reply = dict:to_list(State#state.formats),
|
||||
{reply, Reply, State};
|
||||
handle_call({deregister_format,Key},_From,State) ->
|
||||
NewFormats = dict:erase(Key, State#state.formats),
|
||||
NewState = State#state{formats=NewFormats},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue