Class: Formats
- Inherits:
-
Object
- Object
- Formats
- Defined in:
- lib/fizzbuzz_aj/formats.rb
Instance Method Summary collapse
- #as_html ⇒ Object
- #as_json ⇒ Object
- #as_plain ⇒ Object
- #format_as(fmt) ⇒ Object
-
#initialize(ary) ⇒ Formats
constructor
A new instance of Formats.
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_html ⇒ Object
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_json ⇒ Object
21 22 23 |
# File 'lib/fizzbuzz_aj/formats.rb', line 21 def as_json @ary.to_json end |
#as_plain ⇒ Object
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 |