-
-
Save tbuehlmann/2406288 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'sinatra/base' | |
require 'person' | |
require 'csv' | |
require 'pp' | |
class Application < Sinatra::Base | |
def self.empty_arrays | |
set :people, [] | |
set :pups, [] | |
set :scis, [] | |
set :tpups, [] | |
set :tscis, [] | |
set :both, [] | |
set :extrap, [] | |
end | |
configure do | |
self.empty_arrays | |
end | |
get '/fun' do | |
self.class.empty_arrays | |
file = File.open("finreg.csv", "r") | |
file.each_line do |line| | |
fields = line.split(',') | |
p = Person.new | |
p.surname = fields[0].strip | |
p.forename = fields[1].strip | |
p.age = fields[2].strip | |
p.choice = fields[3].strip | |
if p.choice == "1" | |
settings.pups.push(p) | |
end | |
if p.choice == "2" | |
settings.scis.push(p) | |
end | |
if p.choice =="1" or p.choice == "3" | |
settings.tpups.push(p) | |
end | |
if p.choice =="2" or p.choice == "3" | |
settings.tscis.push(p) | |
end | |
if p.choice == "3" | |
settings.both.push(p) | |
end | |
settings.people.push(p) | |
end | |
output = settings.people.map { |p| "#{p.forename} #{p.surname} (#{p.age.to_s})" } | |
output.join('<br />') | |
end | |
get '/fun/pups' do | |
settings.pups.map { |p| p.printChoice } | |
end | |
get '/fun/all_p' do | |
settings.tpups.map { |p| p.printChoice } | |
end | |
get '/fun/sci' do | |
settings.scis.map { |p| p.printChoice } | |
end | |
get '/fun/all_s' do | |
settings.tscis.map { |p| p.printChoice } | |
end | |
get '/fun/both' do | |
settings.both.map { |p| p.printChoice } | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$LOAD_PATH.unshift(File.dirname(__FILE__)) | |
require 'application' | |
run Application |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Person < Struct.new(:surname, :forename, :age, :choice) | |
def title | |
"<h1>Total Puppets</h1>" | |
end | |
def printName | |
"#{surname}, #{forename}<br />" | |
end | |
def printChoice | |
"#{forename} #{surname} (#{age})<br />" | |
end | |
def to_s | |
"#{self.forename} #{self.surname} #{self.age} #{self.choice} <br />" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment