linguine 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/linguine.rb +61 -3
  2. metadata +1 -1
data/lib/linguine.rb CHANGED
@@ -1,7 +1,65 @@
1
1
  class Linguine
2
+
3
+ attr_reader :terms
2
4
 
3
- def self.hi
4
- puts "Hello world!"
5
+ def initialize(method, text)
6
+ @method = method
7
+ @text = text
8
+ @terms = []
9
+
10
+ collect_terms
5
11
  end
12
+
13
+ private
14
+
15
+ def collect_terms
16
+ @text.split(' ').each do |word|
17
+ @terms << {
18
+ word: word,
19
+ score: scrabble_score(word)
20
+ }
21
+ end
22
+ @terms.sort_by{|t| t[:score]}.reverse
23
+ end
24
+
25
+ def scrabble_score(word)
26
+ score = 0
27
+ word = word.downcase
28
+
29
+ if word.size > 3
30
+ word.scan(/(a|e|i|o|u|l|n|r|s|t)/).each do
31
+ score += 1
32
+ end
33
+
34
+ word.scan(/d|g/).each do
35
+ score += 2
36
+ end
37
+
38
+ word.scan(/(b|c|m|p)/).each do
39
+ score += 3
40
+ end
41
+
42
+ word.scan(/(f|h|v|w|y)/).each do
43
+ score += 4
44
+ end
45
+
46
+ word.scan(/(k)/).each do
47
+ score += 5
48
+ end
49
+
50
+ word.scan(/(j|x)/).each do
51
+ score += 8
52
+ end
53
+
54
+ word.scan(/(q|z)/).each do
55
+ score += 10
56
+ end
57
+ else
58
+ score = 0
59
+ end
60
+
61
+ score
62
+ end
63
+
64
+ end
6
65
 
7
- end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: linguine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: