-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfizzbuzz_generator.rb
More file actions
49 lines (41 loc) · 1.08 KB
/
Copy pathfizzbuzz_generator.rb
File metadata and controls
49 lines (41 loc) · 1.08 KB
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
# FizzBuzz_Generator.rb
require 'json'
require 'rspec'
class FizzBuzzGenerator
def initialize(high_value = 0)
@highest_value = high_value
end
def generate
@output_array = []
@output_array << "Zero, negative numbers, and nil not supported" if (@highest_value <= 0 || @highest_value == nil)
if @highest_value > 0 then
for test_number in 1..@highest_value do
@output_array << "#{test_number} fizz" if (test_number % 3 == 0 && test_number % 5 != 0)
@output_array << "#{test_number} buzz" if (test_number % 5 == 0 && test_number % 3 != 0)
@output_array << "#{test_number} fizzbuzz" if (test_number % 15 == 0)
@output_array << "#{test_number}" if (test_number % 3 != 0 && test_number % 5 != 0)
end
end
end
def print
@output_array.each do |line|
puts line
end
end
def html
htm = "<ul>\n"
@output_array.each do |line|
htm += " <li> #{line} </li> \n"
end
htm = htm += "</ul>"
return htm
end
def json
@output_array.to_json.to_json
end
end
#doit = FizzBuzzGenerator.new(15)
#doit.generate
#doit.print
#doit.html
#puts doit.json