-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode_erb.rb
67 lines (52 loc) · 1.52 KB
/
code_erb.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
# Team: Nick, Jake, Jake, Drake
require 'erb'
recipe = {
name: "Roasted Brussels Sprouts",
ingredients: [
"1 1/2 pounds Brussels sprouts",
"3 tablespoons good olive oil",
"3/4 teaspoon kosher salt",
"1/2 teaspoon freshly ground black pepper"
],
directions: [
"Preheat oven to 400 degrees F.",
"Cut off the brown ends of the Brussels sprouts.",
"Pull off any yellow outer leaves.",
"Mix them in a bowl with the olive oil, salt and pepper.",
"Pour them on a sheet pan and roast for 35 to 40 minutes.",
"They should be until crisp on the outside and tender on the inside.",
"Shake the pan from time to time to brown the sprouts evenly.",
"Sprinkle with more kosher salt ( I like these salty like French fries).",
"Serve and enjoy!"
]
}
recipe_title = "Recipe: #{recipe[:name]}"
def ingredient_list(item)
inglist = ""
item.each do |ingredient|
inglist << "- #{ingredient}\n"
end
return inglist
end
def instructions_list(item)
inslist = ""
item.each_with_index do |instruction, index|
inslist << "#{index+1}. #{instruction}\n\n".rjust(80)
end
return inslist
end
ingredient_summary = "#{ingredient_list(recipe[:ingredients])}"
instruction_summary = "#{instructions_list(recipe[:directions])}"
recipe_template = <<-ERB
#=<%= "=" * recipe_title.length %>=#
# <%= recipe_title %> #
#=<%= "=" * recipe_title.length %>=#
Ingredients
-----------
<%= ingredient_summary%>
Directions
----------
<%= instruction_summary %>
ERB
erb = ERB.new(recipe_template)
puts erb.result