Class: Shiba::Review::CommentRenderer

Inherits:
Object
  • Object
show all
Defined in:
lib/shiba/review/comment_renderer.rb

Constant Summary collapse

VAR_PATTERN =

variable }

/{{\s?([a-z_]+)\s?}}/

Instance Method Summary collapse

Constructor Details

#initialize(templates) ⇒ CommentRenderer

Returns a new instance of CommentRenderer.



9
10
11
# File 'lib/shiba/review/comment_renderer.rb', line 9

def initialize(templates)
  @templates = templates
end

Instance Method Details

#render(explain) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/shiba/review/comment_renderer.rb', line 13

def render(explain)
  body = ""

  explain["messages"].each do |message|
    tag = message['tag']
    data = present(message)
    data.merge!(explain["global"])
    body << " * "
    body << @templates[tag]["title"]
    body << ": "
    body << render_template(@templates[tag]["summary"], data)
    body << "\n"
  end

  body << " * Estimated query time: %.2fs" % explain['cost']
  body
end