Class: Lurker::JsonPresenter

Inherits:
Object
  • Object
show all
Defined in:
lib/lurker/presenters/json_presenter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json) ⇒ JsonPresenter

Returns a new instance of JsonPresenter.



6
7
8
# File 'lib/lurker/presenters/json_presenter.rb', line 6

def initialize(json)
  @json = json
end

Instance Attribute Details

#jsonObject (readonly)

Returns the value of attribute json.



4
5
6
# File 'lib/lurker/presenters/json_presenter.rb', line 4

def json
  @json
end

Instance Method Details

#to_htmlObject



10
11
12
13
14
15
16
17
18
19
20
21
# 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