TextSearch
TextSearch allows to count the number of occurrences of a word in a text.
Installation
Add this line to your application's Gemfile:
gem 'text_search'
And then execute:
$ bundle
Or install it yourself as:
$ gem install text_search
Usage
require 'text_search'
# Search from web
text = TextSearch::Web.new('www.google.com',["google"])
text.search
#=> [{"google"=>3}, {"youtube"=>1}]
# Search from text
text = TextSearch::Text.new('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.',["ipsum","test"])
text.search
#=> [{"ipsum"=>2}, {"test"=>0}]
# Show words from text/web
text = TextSearch::Text.new('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.')
text.words
#=> ["lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipiscing", "elit", "integer", "nec", "odio", "praesent", "libero", "sed", "cursus", "ante", "dapibus", "diam", "sed", "nisi", "nulla", "quis", "sem", "at", "nibh", "elementum", "imperdiet", "duis", "sagittis", "ipsum", "praesent", "mauris", "fusce", "nec", "tellus", "sed", "augue", "semper", "porta", "mauris", "massa", "vestibulum", "lacinia", "arcu", "eget", "nulla", "class", "aptent", "taciti", "sociosqu", "ad", "litora", "torquent", "per", "conubia", "nostra", "per", "inceptos", "himenaeos"]
Development
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
to create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Contributing
- Fork it ( https://github.com/[my-github-username]/text_search/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request