Class: RhetButler::Web::QrDisplayApp

Inherits:
Object
  • Object
show all
Defined in:
lib/rhet-butler/web/qr-display-app.rb

Defined Under Namespace

Classes: QRItem

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(files, path) ⇒ QrDisplayApp

Returns a new instance of QrDisplayApp.



6
7
8
9
10
# File 'lib/rhet-butler/web/qr-display-app.rb', line 6

def initialize(files, path)
  @config = files.aspect_config(:presenter)
  @templates = files.aspect_templates(:presenter)
  @path = path
end

Instance Attribute Details

#template_handlerObject (readonly)

Returns the value of attribute template_handler.



12
13
14
# File 'lib/rhet-butler/web/qr-display-app.rb', line 12

def template_handler
  @template_handler
end

Instance Method Details

#call(env) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rhet-butler/web/qr-display-app.rb', line 16

def call(env)
  url = [env["rack.url_scheme"], "://"]
  if env["HTTP_HOST"].nil? or env["HTTP_HOST"].empty?
    url << env["SERVER_NAME"]
    url << ":"
    url << env["SERVER_PORT"]
  else
    url << env["HTTP_HOST"]
  end
  view_url = url.join("") + "/"

  url << @path
  url = url.join("")
  qr = RQRCode::QRCode.new(url, :size => 5)

  mime_type = "text/html"
  qr_item = QRItem.new(qr, view_url, url)
  generator = HTMLGenerator.new(@config, @templates)
  [200, {'Content-Type' => mime_type}, [
    generator.render("presenter-qr.html", qr_item)
  ]]
end