-
Notifications
You must be signed in to change notification settings - Fork 1
/
hello.rb
105 lines (87 loc) · 2.37 KB
/
hello.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
90
91
92
93
94
require './student.rb'
# CHALLENGE: Try to use the Student.all method
# to get the list of students
# and change this code to use the list instead
# of the hardcoded array below.
array_of_student_hashes = [
{
'first_name' => 'Ian',
'last_name' => 'Gerstel',
'hometown' => 'Chicago'
},
{
'first_name' => 'Jordan',
'last_name' => 'Leigh',
'hometown' => 'Chicago'
},
{
'first_name' => 'Connor',
'last_name' => 'Lynch',
'hometown' => 'Chicago'
},
{
'first_name' => 'Ian',
'last_name' => 'Margolis',
'hometown' => 'Chicago'
},
{
'first_name' => 'Mona',
'last_name' => 'Parikh',
'hometown' => 'Chicago'
}, {
'first_name' => 'Gurban',
'last_name' => 'Haydarov',
'hometown' => 'Chicago'
},
{
'first_name' => 'Jordan',
'last_name' => 'Curnes',
'hometown' => 'Chicago'
},
{
'first_name' => 'Shaan',
'last_name' => 'Shah',
'hometown' => 'Chicago'
}
]
def to_string(student)
"#{student['first_name']} #{student['last_name']} is from #{student['hometown']}."
end
def to_html(student)
"<li class='frame'>
<img class='thumbnail' width='200' height='200' src='images/#{student['first_name']} #{student['last_name']}.jpg'>
<p class='name'>#{student['first_name']} #{student['last_name']}</p>
<p class='hometown'>Chicago</p>
</li>"
end
def output_to_terminal(students)
puts 'HELLO CODE ACADEMY'
puts '------------------'
students.each do |student_hash|
puts to_string student_hash
end
end
def output_to_browser(students)
f = File.new('hello.html', 'w')
f.puts "<html>"
f.puts " <head>"
f.puts " <title>Hello CA</title>"
f.puts " <link rel='stylesheet' href='reset.css' type='text/css'>"
f.puts " <link rel='stylesheet' href='styles.css' type='text/css'>"
f.puts " <link href='http://fonts.googleapis.com/css?family=Arvo' rel='stylesheet' type='text/css'>"
f.puts " </head>"
f.puts " <body>"
f.puts " <h1>"
f.puts " Hello Code Academy"
f.puts " </h1>"
f.puts " <ul>"
students.each do |student_hash|
f.puts to_html(student_hash)
end
f.puts " </ul>"
f.puts " </body>"
f.puts "</html>"
f.close
end
output_to_terminal(array_of_student_hashes)
output_to_browser(array_of_student_hashes)