Skip to content

Commit

Permalink
Initial scores now built depending or html tag
Browse files Browse the repository at this point in the history
id or class name.

This is faster and done in one walk of tree than
building score by id or class name for each parent
of <p> tag when walking is done so many times as
<p> tags exist in tree.

So score_one_p function is not required yet,
because scoring by commas should be done with 
parent, not with <p> itself (because <p> is empty
and number of "," == 0)
  • Loading branch information
ivkosh committed Jan 29, 2011
1 parent 5573269 commit 533272f
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/rdbl.erl
Expand Up @@ -286,7 +286,7 @@ init_scores(Tree) -> init_scores(Tree, make_ref()). % adding reference for topmo
%
init_scores(R, _) when is_binary(R) -> R;
init_scores({comment, _}, _) -> []; % dropping comments
init_scores({E, A, Rest}, Parent) -> Ref=make_ref(), {E, #score{ref=Ref, parent=Parent}, A, init_scores(Rest, Ref)}; % setting current parent and giving my ref to child as parent
init_scores({E, A, Rest}, Parent) -> Ref=make_ref(), {E, #score{ref=Ref, parent=Parent, readability=score_by_class_or_id(A)}, A, init_scores(Rest, Ref)}; % setting current parent and giving my ref to child as parent
init_scores([], _) -> [];
init_scores([H|T], Parent) -> [init_scores(H, Parent) | init_scores(T, Parent)]. % processing list recursively

Expand Down Expand Up @@ -374,9 +374,10 @@ get_score(Node) ->
Score.

%% @spec score_by_class_or_id(scored_html_node()) -> int()
%% @spec score_by_class_or_id([html_attr()]) -> int()
%% @doc calculates score for node element by its id or class name
score_by_class_or_id(Node) ->
{_, _, Attrs, _} = Node,
score_by_class_or_id({_, _, Attrs, _})-> score_by_class_or_id(Attrs).
score_by_class_or_id(Attrs) when is list Attrs ->
AttrVals = [ V || {K, V} <- Attrs, (K == <<"id">>) or (K == <<"class">>) ],
if
AttrVals == [] -> 0; % no id or class (list is empty)
Expand Down

0 comments on commit 533272f

Please sign in to comment.