diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..0f645eb --- /dev/null +++ b/Gemfile @@ -0,0 +1,5 @@ +source 'https://rubygems.org' + +gem 'sinatra', '~>1.4.7' +gem 'rerun', '~>0.11.0' +gem 'thin', '~>1.6.4' \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..30ccb77 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,37 @@ +GEM + remote: https://rubygems.org/ + specs: + daemons (1.2.3) + eventmachine (1.2.0.1) + ffi (1.9.10) + listen (3.0.6) + rb-fsevent (>= 0.9.3) + rb-inotify (>= 0.9.7) + rack (1.6.4) + rack-protection (1.5.3) + rack + rb-fsevent (0.9.7) + rb-inotify (0.9.7) + ffi (>= 0.5.0) + rerun (0.11.0) + listen (~> 3.0) + sinatra (1.4.7) + rack (~> 1.5) + rack-protection (~> 1.4) + tilt (>= 1.3, < 3) + thin (1.6.4) + daemons (~> 1.0, >= 1.0.9) + eventmachine (~> 1.0, >= 1.0.4) + rack (~> 1.0) + tilt (2.0.2) + +PLATFORMS + ruby + +DEPENDENCIES + rerun (~> 0.11.0) + sinatra (~> 1.4.7) + thin (~> 1.6.4) + +BUNDLED WITH + 1.11.2 diff --git a/lib/score.rb b/lib/score.rb new file mode 100644 index 0000000..04227f9 --- /dev/null +++ b/lib/score.rb @@ -0,0 +1,76 @@ +class Score + + LETTER_SCORES = { + 1 => ['A', 'E', 'I', 'O', 'U', 'L', 'N', 'R', 'S', 'T'], + 2 => ['D', 'G'], + 3 => ['B', 'C', 'M', 'P'], + 4 => ['F', 'H', 'V', 'W', 'Y'], + 5 => ['K'], + 8 => ['J', 'X'], + 10 => ['Q', 'Z'] + } + + def self.not_a_word?(input_string) + # if string contains punctuation or a number, it will not be nil + return false if /[\W\d]/.match(input_string).nil? || input_string == "" + true + end + + def self.score(word) + # check if word is actually a word (not containing punctuation or numbers) + return "invalid!" if self.not_a_word?(word) + + score_array = self.letter_score(word) + word_score = score_array.reduce(0) do |sum, set| + sum + set[1] + end + + word_score + end + + def self.letter_score(word) + letter_scores = [] + + word.upcase! + letter_array = word.split(//) + + letter_array.each do |letter| + # match is an array, where the first index is the key + # and the second index is the value from the LETTER_SCORES + # constant. + match = LETTER_SCORES.find do |key, value, a| + value.include? letter + end + + # push the key (which is the score of the letter) into the + # letter scores array + letter_scores << match.first unless match.nil? + end + + # zip together the letter array and the scores array to + # create an array of arrays with matching letter and scores + zipped = letter_array.zip(letter_scores) + + zipped << ['bonus', 50] if word.length == 7 + + zipped + end + + def self.string_processing(string_of_words) + # remove any commas that may be separating words + # replace with a space in case there's no space after the commas + string_of_words.gsub!(",", " ") + + array_of_words = string_of_words.split(" ") + end + + def self.score_many(list_of_words) + score_array = [] + + list_of_words.each do |word| + score_array << score(word) + end + + score_array + end +end diff --git a/myapp.rb b/myapp.rb new file mode 100644 index 0000000..f55a956 --- /dev/null +++ b/myapp.rb @@ -0,0 +1,40 @@ +require 'sinatra' +require_relative 'lib/score' + +class MyApp < Sinatra::Base + + get '/' do + @css = "/stylesheets/styles_index.css" + erb :index + end + + get '/score' do + erb :score + end + + get '/score/:word' do + @word = params[:word] + @score = Score.score(@word) + erb :score + end + + post '/score' do + @word = params["game"]["word"] + @score = Score.score(@word) + @letter_scores = Score.letter_score(@word) + erb :score + end + + get '/score-many' do + erb :score_many + end + + post '/score-many' do + @words = Score.string_processing(params["game"]["word_list"]) + @scores = Score.score_many(@words) + @letter_scores = @words.map { |word| Score.letter_score(word) } + erb :score_many + end + + run! +end \ No newline at end of file diff --git a/public/stylesheets/styles.css b/public/stylesheets/styles.css new file mode 100644 index 0000000..93e1a80 --- /dev/null +++ b/public/stylesheets/styles.css @@ -0,0 +1,162 @@ +* { + box-sizing: border-box; +} + +html { + font-size: 16px; + font-family: "Handlee"; + min-height: 100%; + position: relative; +} + +body { + /*background-color: #262626;*/ + background: linear-gradient(#660066, #000); /* Standard syntax */ + background-attachment: fixed; + color: #a6a6a6; + margin: 0; + padding: 0; +} + + +/*********HEADER**********/ + +h1 { + font-size: 5vw; + font-family: "Orbitron", sans-serif; + letter-spacing: 2rem; + text-align: center; + text-shadow: 4px 4px 5px #000; + padding-left: 2rem; /* doesn't look centered wtf */ + width: 100%; +} + +nav { + text-align: center; +} + +nav ul { + list-style: none; + padding: 1rem; + width: 100%; + margin: 0; +} + +nav li { + display: inline-block; + width: 30%; +} + +nav a { + color: #00b8e6; + font-size: 1.5rem; + font-variant: small-caps; + text-decoration: none; + width: 100%; +} + +nav a:hover { + color: #d9d9d9; +} + + +/*********BODY***********/ + +main { + margin-bottom: 100px; +} + +form { + padding: 2rem 0; + text-align: center; +} + +label, input { + display: block; + margin: 1rem auto; +} + +label { + font-size: 2rem; + text-shadow: 2px 2px 5px #000; +} + +form > p { + font-size: 1.2rem; + text-align: center; + text-shadow: 1px 1px 2px #000; +} + +.from-user { + color: #c653c6; + font-size: 2rem; + text-align: center; + width: 25%; + background-color: #262626; +} + +.blank { + width: 100%; + min-height: 100%; +} + +.result { + font-size: 2.5rem; + text-align: center; +} + +table { + font-size: 1.5rem; + border-spacing: 3rem 0.5rem; + border: 1px solid #4d4d4d; + margin: 2rem auto; +} + +th { + font-size: 1.7rem; + text-decoration: underline; +} + +th, td { + padding: 1rem; +} + +.breakdown { + text-align: center; + padding: 2rem; +} + +span.score { + color: #b300b3; + padding: 1rem 2rem 1rem 0.5rem; +} + +.breakdown > p { + margin: 2rem 0; +} + +.many-breakdown { + padding-left: 2rem; +} + +/*********FOOTER**********/ + +footer { + bottom: 0; + color: #b300b3; + font-size: 0.7rem; + margin: 0 auto; + padding: 2rem 0; + position: absolute; + text-align: center; + width: 100%; + height: 100px; +} + +footer p { + margin-bottom: 0.2rem; +} + +footer a { + color: #00b8e6; +} diff --git a/public/stylesheets/styles_index.css b/public/stylesheets/styles_index.css new file mode 100644 index 0000000..a4493e6 --- /dev/null +++ b/public/stylesheets/styles_index.css @@ -0,0 +1,12 @@ +h1 { + font-size: 8.5vw; + margin: 8rem auto; +} + +li.home { + display: none; +} + +nav a { + font-size: 2rem; +} \ No newline at end of file diff --git a/public/stylesheets/styles_score_many.css b/public/stylesheets/styles_score_many.css new file mode 100644 index 0000000..cce8fb1 --- /dev/null +++ b/public/stylesheets/styles_score_many.css @@ -0,0 +1,8 @@ +/*.result-many { + column-count: 4; + -webkit-column-count: 4; + -moz-column-count: 4;*/ +/* column-rule: solid; + -webkit-column-rule: solid; + -moz-column-rule: solid; +}*/ \ No newline at end of file diff --git a/views/index.erb b/views/index.erb new file mode 100644 index 0000000..e69de29 diff --git a/views/layout.erb b/views/layout.erb new file mode 100644 index 0000000..a3e5769 --- /dev/null +++ b/views/layout.erb @@ -0,0 +1,33 @@ + + +
+ + + + + <%= "" if @css %> +<%= "#{@word}: #{@score}" %>
+Word | +Score | +Breakdown | +
---|---|---|
<%= @words[i] %> | +<%= score %> | ++ + <% @letter_scores[i].each do |pair| %> + <%= pair.first + ": " %> + <%= pair[1] %> + <% end %> + | +