Class: DurationRenderer

Inherits:
ResourceRenderer::AttributeRenderer::Base show all
Defined in:
app/attribute_renderers/duration_renderer.rb

Instance Attribute Summary

Attributes inherited from ResourceRenderer::AttributeRenderer::Base

#helper, #model

Instance Method Summary collapse

Methods inherited from ResourceRenderer::AttributeRenderer::Base

#initialize

Constructor Details

This class inherits a constructor from ResourceRenderer::AttributeRenderer::Base

Instance Method Details

#display(attribute_name, label, options = {}, &block) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/attribute_renderers/duration_renderer.rb', line 2

def display(attribute_name, label, options = {}, &block)
  return  h.capture { block.call(resource) } if block_given?

  options.reverse_merge!(input_unit: :seconds)
  input_unit = options.delete(:input_unit)

  input_duration = value_for_attribute(attribute_name)
  seconds = duration_in_seconds(input_duration, input_unit)

  html_attributes = {

  }

  helper.capture do
    h.(:span, html_attributes) { humanize(seconds) }
  end
end