Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Controller for Word counted gem
class WordCountController < ApplicationController
def index
@sentence = 'Keyword density is the percentage of times a keyword or phrase appears on a web page compared to the total number of words on the page. In the context of search engine optimization keyword density can be used as a factor in determining whether a web page is relevant to a specified keyword or keyword phrase.
In the late 1990s, which was the early days of search engines, keyword density was an important factor in how a page was ranked. However, as webmasters discovered this and the implementation of optimum keyword density became widespread, it became a minor factor in the rankings. Search engines began giving priority to other factors that are beyond the direct control of webmasters. Today, the overuse of keywords, a practice called keyword stuffing, will cause a web page to be penalized.
Many SEO experts consider the optimum keyword density to be 1 to 3 percent. Using a keyword more than that could be considered search spam. The formula to calculate your keyword density on a web page for SEO purposes is (Nkr/Tkn)*100, where Nkr is how many times you repeated a specific keyword and Tkn the total words in the analyzed text. This will result in a keyword density value. When calculating keyword density, be sure to ignore html tags and other embedded tags which will not actually appear in the text of the page once it is published. '
@counter_with_stop_words = WordsCounted.count(@sentence)
@counter = WordsCounted.count(@sentence, exclude: ApplicationHelper::STOP_WORDS)
@price = (@counter_with_stop_words.token_count.to_f / WORDS_PER_BUNCH).ceil * CHARGE_PER_WORDS_BUNCH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment