PageRenderTime 92ms CodeModel.GetById 60ms app.highlight 7ms RepoModel.GetById 24ms 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
20-include("uce.hrl").
21
22-export([print/2]).
23
24%%
25%% Print uce records
26%%
27print(Records, flat) when is_list(Records) ->
28    lists:flatten([print(Record, flat) ++ "--~n" || Record <- Records]);
29print(#uce_meeting{id=Id,
30                   metadata=Metadata}, flat) ->
31    Out = [io_lib:format("Id: ~s~n", [Id])],
32    StrMetadata = print_metadata(Metadata),
33    lists:flatten(Out ++ StrMetadata);
34print(#uce_user{id=Uid,
35                name=Name,
36                auth=Auth,
37                metadata=Metadata,
38                roles=Roles}, flat) ->
39    Out = [io_lib:format("Id: ~s~n", [Uid]),
40           io_lib:format("Name: ~s~n", [Name]),
41           io_lib:format("Authentification method: ~s~n", [Auth])],
42    StrMetadata = print_metadata(Metadata),
43    StrRoles =
44        if
45            Roles == [] ->
46                ["Roles: none~n"];
47            true ->
48                [io_lib:format("Roles:~n", [])] ++
49                    [ if
50                          Location == "" ->
51                              io_lib:format("\t~s in all locations~n", [Role]);
52                          true ->
53                              io_lib:format("\t~s in ~s~n", [Role, Location])
54                      end || {Role, Location} <- Roles ]
55        end,
56    lists:flatten(Out ++ StrMetadata ++ StrRoles).
57
58print_metadata({struct, Metadata}) ->
59    print_metadata(Metadata);
60print_metadata([]) ->
61    ["Metadata: none~n"];
62print_metadata(Metadata) ->
63    [io_lib:format("Metadata:~n", [])] ++
64        [ io_lib:format("\t~s: ~s~n", [Key, Value]) || {Key, Value} <- Metadata ].