Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lisa's Scrabble Sinatra site #14

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
e813f89
gemfile and .lock
Lisa-Sano Apr 6, 2016
04ce631
first commit of views
Lisa-Sano Apr 6, 2016
e0df0c1
first commit of score.rb
Lisa-Sano Apr 6, 2016
2150f65
first commit of myapp.rb
Lisa-Sano Apr 6, 2016
5188f9c
made self.score_many work and show the word and score on the screen f…
Lisa-Sano Apr 6, 2016
d7aaa03
added nav links to the different pages
Lisa-Sano Apr 6, 2016
76b359b
removed nav links since they were moved to layout.erb
Lisa-Sano Apr 6, 2016
4a9cf46
separate the parameter being passed to Score class methods into anoth…
Lisa-Sano Apr 7, 2016
20d0d0d
prints out the name and the score
Lisa-Sano Apr 7, 2016
9a40be8
basic styling of nav bar and background
Lisa-Sano Apr 7, 2016
081858b
added content to footer and link to style sheet
Lisa-Sano Apr 7, 2016
cd36954
added footer styling so it's centered at the bottom of the page
Lisa-Sano Apr 7, 2016
fb617f8
added a new method to determine whether the word or list of words giv…
Lisa-Sano Apr 7, 2016
2d7297d
Adding styling to the <main> part of the pages containing forms and o…
Lisa-Sano Apr 7, 2016
36618c3
Updated what is displayed and what the label for the input box says.
Lisa-Sano Apr 7, 2016
5d23c88
small tweak of footer info and home link
Lisa-Sano Apr 7, 2016
2b8a77e
Added a table to display the results for multiple words entered, and …
Lisa-Sano Apr 7, 2016
f287bee
changed nav bar link text
Lisa-Sano Apr 7, 2016
606ba74
new method self.letter_score returns an array of arrays containing le…
Lisa-Sano Apr 9, 2016
e245efe
added new font links, changed footer mail subject, and changed h1 text
Lisa-Sano Apr 9, 2016
494a33c
show each letter and value when words are scored
Lisa-Sano Apr 9, 2016
03e10f9
added specific stylesheet for home page. added get request for /score…
Lisa-Sano Apr 9, 2016
531aaae
changed style of h1. added styling for printing out letters and their…
Lisa-Sano Apr 9, 2016
337059d
prints out letters and their individual values when a word is scored
Lisa-Sano Apr 9, 2016
b121110
the display of /score-many now shows the score breakdown by letter in…
Lisa-Sano Apr 10, 2016
de40674
forgot to add this file to last commit. added self.string_processing …
Lisa-Sano Apr 10, 2016
13d5102
added styling for the breakdown of individual letter scores
Lisa-Sano Apr 10, 2016
a2f8807
updated methods so bonus is added in letter_score
Lisa-Sano Apr 11, 2016
25fddeb
made all index specific changes in index stylesheet so nothing needed…
Lisa-Sano Apr 11, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source 'https://rubygems.org'

gem 'sinatra', '~>1.4.7'
gem 'rerun', '~>0.11.0'
gem 'thin', '~>1.6.4'
37 changes: 37 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -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
76 changes: 76 additions & 0 deletions lib/score.rb
Original file line number Diff line number Diff line change
@@ -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
40 changes: 40 additions & 0 deletions myapp.rb
Original file line number Diff line number Diff line change
@@ -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
162 changes: 162 additions & 0 deletions public/stylesheets/styles.css
Original file line number Diff line number Diff line change
@@ -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;
}
12 changes: 12 additions & 0 deletions public/stylesheets/styles_index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
h1 {
font-size: 8.5vw;
margin: 8rem auto;
}

li.home {
display: none;
}

nav a {
font-size: 2rem;
}
8 changes: 8 additions & 0 deletions public/stylesheets/styles_score_many.css
Original file line number Diff line number Diff line change
@@ -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;
}*/
Empty file added views/index.erb
Empty file.
33 changes: 33 additions & 0 deletions views/layout.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="/stylesheets/styles.css">
<link href='https://fonts.googleapis.com/css?family=Handlee' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Orbitron' rel='stylesheet' type='text/css'>
<%= "<link rel='stylesheet' type='text/css' href='#{@css}'>" if @css %>
<title>Scrabble!</title>
</head>

<body>
<header>
<h1>SCRABBLE</h1>
<nav>
<ul>
<li class="home"><a href="/">Go Home</a></li>
<li><a href="/score">Score a word</a></li>
<li><a href="/score-many">Score many words</a></li>
</ul>
</nav>
</header>

<main>
<%= yield %>
</main>

<footer>
<p>© 2016 Lisa Rolczynski</p>
<a href="mailto:[email protected]?Subject=Hey%20Lisa%20you%20so%20cool" target="_top">Contact me!</a>
</footer>
</body>
</html>
Loading