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.



187
188
189
190
# File 'lib/decisive/template_handler.rb', line 187

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



184
185
186
# File 'lib/decisive/template_handler.rb', line 184

def columns
  @columns
end

#filenameObject

Returns the value of attribute filename

Returns:

  • (Object)

    the current value of filename



184
185
186
# File 'lib/decisive/template_handler.rb', line 184

def filename
  @filename
end

#recordsObject

Returns the value of attribute records

Returns:

  • (Object)

    the current value of records



184
185
186
# File 'lib/decisive/template_handler.rb', line 184

def records
  @records
end

Instance Method Details

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

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



192
193
194
195
196
# File 'lib/decisive/template_handler.rb', line 192

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

#csv?Boolean

Returns:

  • (Boolean)


209
210
211
# File 'lib/decisive/template_handler.rb', line 209

def csv?
  true
end

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

Yields:

  • (header)


198
199
200
201
202
203
204
205
206
207
# File 'lib/decisive/template_handler.rb', line 198

def each
  yield header

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