Class: Formats

Inherits:
Object
  • Object
show all
Defined in:
lib/fizzbuzz_aj/formats.rb

Instance Method Summary collapse

Constructor Details

#initialize(ary) ⇒ Formats

Returns a new instance of Formats.



3
4
5
# File 'lib/fizzbuzz_aj/formats.rb', line 3

def initialize ary
  @ary = ary
end

Instance Method Details

#as_htmlObject



25
26
27
28
29
30
31
# File 'lib/fizzbuzz_aj/formats.rb', line 25

def as_html
  <<-EOF
    <ul>
    #{@ary.map { |d| "<li>#{d}</li>"}.join("\n\t")}
    </ul>
  EOF
end

#as_jsonObject



21
22
23
# File 'lib/fizzbuzz_aj/formats.rb', line 21

def as_json
  @ary.to_json
end

#as_plainObject



17
18
19
# File 'lib/fizzbuzz_aj/formats.rb', line 17

def as_plain
  @ary.join(", ")
end

#format_as(fmt) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/fizzbuzz_aj/formats.rb', line 7

def format_as fmt
  if(fmt == "html")
    as_html
    elseif (fmt == "json")
    as_json
  else
    as_plain
  end
end