PageRenderTime 25ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/ucengine/src/helpers/pretty_print.erl

http://github.com/AF83/ucengine
Erlang | 64 lines | 40 code | 4 blank | 20 comment | 5 complexity | 5b0d5b5802052bf159fdca76c56a3ea2 MD5 | raw file
  1. %%
  2. %% U.C.Engine - Unified Collaboration Engine
  3. %% Copyright (C) 2011 af83
  4. %%
  5. %% This program is free software: you can redistribute it and/or modify
  6. %% it under the terms of the GNU Affero General Public License as published by
  7. %% the Free Software Foundation, either version 3 of the License, or
  8. %% (at your option) any later version.
  9. %%
  10. %% This program is distributed in the hope that it will be useful,
  11. %% but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. %% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. %% GNU Affero General Public License for more details.
  14. %%
  15. %% You should have received a copy of the GNU Affero General Public License
  16. %% along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. %%
  18. -module(pretty_print).
  19. -include("uce.hrl").
  20. -export([print/2]).
  21. %%
  22. %% Print uce records
  23. %%
  24. print(Records, flat) when is_list(Records) ->
  25. lists:flatten([print(Record, flat) ++ "--~n" || Record <- Records]);
  26. print(#uce_meeting{id=Id,
  27. metadata=Metadata}, flat) ->
  28. Out = [io_lib:format("Id: ~s~n", [Id])],
  29. StrMetadata = print_metadata(Metadata),
  30. lists:flatten(Out ++ StrMetadata);
  31. print(#uce_user{id=Uid,
  32. name=Name,
  33. auth=Auth,
  34. metadata=Metadata,
  35. roles=Roles}, flat) ->
  36. Out = [io_lib:format("Id: ~s~n", [Uid]),
  37. io_lib:format("Name: ~s~n", [Name]),
  38. io_lib:format("Authentification method: ~s~n", [Auth])],
  39. StrMetadata = print_metadata(Metadata),
  40. StrRoles =
  41. if
  42. Roles == [] ->
  43. ["Roles: none~n"];
  44. true ->
  45. [io_lib:format("Roles:~n", [])] ++
  46. [ if
  47. Location == "" ->
  48. io_lib:format("\t~s in all locations~n", [Role]);
  49. true ->
  50. io_lib:format("\t~s in ~s~n", [Role, Location])
  51. end || {Role, Location} <- Roles ]
  52. end,
  53. lists:flatten(Out ++ StrMetadata ++ StrRoles).
  54. print_metadata({struct, Metadata}) ->
  55. print_metadata(Metadata);
  56. print_metadata([]) ->
  57. ["Metadata: none~n"];
  58. print_metadata(Metadata) ->
  59. [io_lib:format("Metadata:~n", [])] ++
  60. [ io_lib:format("\t~s: ~s~n", [Key, Value]) || {Key, Value} <- Metadata ].