In Nakayama's book 2004, pg. 39, a formula is written:
Let $f:X \to Y$ be a generically finite and proper surjective morphism, $D$ be a Cartier divisor on $Y$. Then, $f_*f^*D=(\deg f) D$.
More precisely, we can compute in this way. Let $\sum_i D_i$ be a reduced divisor on $X$ of all prime divisors mapped onto $D$. Then, $f^*D= \sum_i r_iD_i$ where $r_i$ is the ramification index of $D_i$. Since $f_*D_i =(\deg f|_{D_i}) D$ by definition, we have $f_*f^*D= \sum_i r_i (\deg f|_{D_i}) D =(\deg f) D$.
Here is my question:
(1) why define $f_*D_i =(\deg f|_{D_i}) D$?
(2) why $\sum_i r_i(\deg f|_{D_i}) =\deg f$?
where can I find a detailed reference for these formulae? I try to search on Stacks but I cannot find a detailed answer.
Thank you!