Class: Decisive::StreamContext

Inherits:
Struct
  • Object
show all
Defined in:
lib/decisive/template_handler.rb

Defined Under Namespace

Classes: Column

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, &block) ⇒ StreamContext

Returns a new instance of StreamContext.



64
65
66
67
# File 'lib/decisive/template_handler.rb', line 64

def initialize *args, &block
  super
  instance_eval &block
end

Instance Attribute Details

#columnsObject

Returns the value of attribute columns

Returns:

  • (Object)

    the current value of columns



61
62
63
# File 'lib/decisive/template_handler.rb', line 61

def columns
  @columns
end

#filenameObject

Returns the value of attribute filename

Returns:

  • (Object)

    the current value of filename



61
62
63
# File 'lib/decisive/template_handler.rb', line 61

def filename
  @filename
end

#recordsObject

Returns the value of attribute records

Returns:

  • (Object)

    the current value of records



61
62
63
# File 'lib/decisive/template_handler.rb', line 61

def records
  @records
end

Instance Method Details

#column(label, value = nil, &block) ⇒ Object

field, label: field.to_s.humanize, &block



69
70
71
72
73
# File 'lib/decisive/template_handler.rb', line 69

def column label, value=nil, &block # field, label: field.to_s.humanize, &block
  value ||= label.parameterize.underscore.to_sym
  block ||= ->(record) { record.send(value) }
  columns << Column.new(label, block)
end

#each {|header| ... } ⇒ Object

Yields:

  • (header)


75
76
77
78
79
80
81
82
83
84
# File 'lib/decisive/template_handler.rb', line 75

def each
  yield header

  records.map do |record|
    row = columns.map do |column|
      column.block.call(record).to_s
    end
    yield row
  end
end