Advertisement
Guest User

keyword_count.rb

a guest
Sep 23rd, 2013
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 0.25 KB | None | 0 0
  1. class KeywordCount
  2.   attr_reader :keywords, :text
  3.  
  4.   def initialize(keywords, text)
  5.     @keywords = keywords
  6.     @text = text
  7.   end
  8.  
  9.   def counts
  10.     @counts ||= keywords.inject({}) do |h, kw|
  11.       h[kw] = text.scan(kw).lenth; h
  12.     end
  13.   end
  14. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement