forked from dfriedm/nycstreetsweep
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.rb
89 lines (66 loc) · 2.42 KB
/
app.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# Require all Ruby gems located in Gemfile.
require 'bundler'
Bundler.require
# Include all models in /lib/*/ folders.
require_relative 'environment'
# Use Better Errors for debugging.
use BetterErrors::Middleware
BetterErrors.application_root = __FILE__
module NycStreetSweep
class App < Sinatra::Base
# Route => Default view at index page.
get '/' do
# Define all variables for template.
map_gen = false
@main = ""
@from = ""
@to = ""
@side = ""
@text = "(optional)"
@tweet = "(optional)"
# Setup regulation string for web page print.
@regulation_str = "PLEASE ENTER ADDRESS INFORMATION TO SEE MATCHING REGULATION."
# Generate Javascript to be used in template for map display.
@map_javascript = MapGenerator.generate_js(map_gen)
erb :index
end
# Route => View seen when form is submitted.
post '/' do
# Define all variables for template.
map_gen = true
@main = params[:main_st].upcase
@from = params[:from_st].upcase
@to = params[:to_st].upcase
@side = params[:side_st].upcase
@text = params[:text]
@tweet = params[:tweet]
# Determine regulation based on template values.
parse_values = Parser.parse_info(@main,@from,@to,@side)
days_of_week = ""
parse_values[1].each do |x|
if parse_values[1].length == 2
if x == parse_values[1].last
days_of_week << " and #{x}."
else
days_of_week << "#{x} "
end
else
if x == parse_values[1].last
days_of_week << " and #{x}."
else
days_of_week << "#{x}, "
end
end
end
# Setup regulation string for web page print.
@regulation_str = "Street cleaning takes place between #{parse_values[0][0].strftime("%k:%M%p")} and #{parse_values[0][1].strftime("%k:%M%p")}\non #{days_of_week}"
# Generate Javascript to be used in template for map display.
@map_javascript = MapGenerator.generate_js(map_gen,@main,@from,@to)
# Text and Tweet regulation info.
msg = "Please move your car by #{parse_values[0][0].strftime("%k:%M%p")}! #NYCStreetSweep"
Text.send(@text,msg) if @text.length > 0 && @text != "(optional)"
Tweet.send(@tweet,msg) if @tweet.length > 0 && @tweet != "(optional)"
erb :index
end
end
end