Permalink
Browse files

Initial scores now built depending or html tag

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...
1 parent 5573269 commit 533272f56a1b4a79ea151d2e34bbea8a78f7827d @ivkosh committed Jan 29, 2011
Showing with 4 additions and 3 deletions.
  1. +4 −3 src/rdbl.erl
View
@@ -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
@@ -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)

0 comments on commit 533272f

Please sign in to comment.