Class: CommentCheck
Instance Method Summary collapse
- #analyze(review, wordselection, total) ⇒ Object
- #call(text, wordselection) ⇒ Object
- #load_file(file) ⇒ Object
- #sentiment_type(total) ⇒ Object
Instance Method Details
#analyze(review, wordselection, total) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/commentcheck.rb', line 11 def analyze(review, wordselection, total) #Empty array for results result = Array.new #Split review into sepearte words words = review.split #Then for every word check if that word exists in the JSON file of words words.each do |word| score = wordselection[word].to_f total += score result << { key: word, score: total} end {total: total} end |
#call(text, wordselection) ⇒ Object
5 6 7 8 9 |
# File 'lib/commentcheck.rb', line 5 def call(text, wordselection) sentiment = analyze(text, wordselection, total=0) sentiment[:type] = sentiment_type(sentiment[:total]) sentiment end |
#load_file(file) ⇒ Object
41 42 43 44 |
# File 'lib/commentcheck.rb', line 41 def load_file(file) file = JSON.parse(File.read(file)) return file end |
#sentiment_type(total) ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/commentcheck.rb', line 29 def sentiment_type(total) case when total < 0 'Negative' when total == 0 'Neutral' when total > 0 'Positive' end end |