Class: Tempo::Views::Formatters::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/tempo/views/formatters/base.rb

Direct Known Subclasses

Interactive, Screen

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Base

Returns a new instance of Base.



16
17
18
# File 'lib/tempo/views/formatters/base.rb', line 16

def initialize(options={})
  @options = options
end

Instance Method Details

#format_records(records) ⇒ Object

Here we check if our class methods include a proc block to handle the particular record type. See View Records for all possible record types. See screen formatter for examples of proc blocks.



35
36
37
38
39
# File 'lib/tempo/views/formatters/base.rb', line 35

def format_records(records)
  records.each do |record|
    report record
  end
end

#format_records_container(container) ⇒ Object

Records containers handle nested records



42
43
44
45
46
47
48
# File 'lib/tempo/views/formatters/base.rb', line 42

def format_records_container(container)
  report container.pre if container.pre
  container.records.each do |record|
    report record
  end
  report container.post if container.post
end

#report(record) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/tempo/views/formatters/base.rb', line 20

def report(record)
  class_block = "#{record.type}_block"

  # We handle containers separately
  if /container/.match class_block
    format_records_container(record)
  else
    send(class_block, record) if respond_to? class_block
  end
end