class Lurker::JsonPresenter

Attributes

json[R]

Public Class Methods

new(json) click to toggle source
# File lib/lurker/presenters/json_presenter.rb, line 6
def initialize(json)
  @json = json
end

Public Instance Methods

to_html() click to toggle source
# File lib/lurker/presenters/json_presenter.rb, line 10
def to_html
  if json.is_a? String
    '<tt>&quot;%s&quot;</tt>' % json.gsub(/\"/, 'quot;')
  elsif json.is_a?(Numeric) ||
        json.is_a?(TrueClass) ||
        json.is_a?(FalseClass)
    '<tt>%s</tt>' % json
  elsif json.is_a?(Hash) ||
        json.is_a?(Array)
    '<pre><code>%s</code></pre>' % JSON.pretty_generate(json)
  end
end