-
-
Save atkolkma/6580427 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
class FizzBuzz | |
require 'json' | |
def initialize (input) | |
@max = input | |
end | |
def modulo_parse (n) | |
if n % 15 == 0 | |
"fizzbuzz" | |
elsif n % 5 == 0 | |
"buzz" | |
elsif n % 3 == 0 | |
"fizz" | |
else | |
n.to_s | |
end | |
end | |
def fizzbuzzer | |
(1..@max).map do |n| | |
modulo_parse (n) | |
end | |
end | |
def as_text () | |
fizzbuzzer().join(", ") | |
end | |
def as_json | |
fizzbuzzer().to_json | |
end | |
def as_html | |
<<-EOF | |
<html> | |
<body> | |
#{(1..@max).map {|n| "<li> #{modulo_parse(n)} </li>"}.join("\n\t")} | |
</body> | |
</html> | |
EOF | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment