Class: Decisive::StreamContext
- Inherits:
-
Struct
- Object
- Struct
- Decisive::StreamContext
- Defined in:
- lib/decisive/template_handler.rb
Defined Under Namespace
Classes: Column
Instance Attribute Summary collapse
-
#columns ⇒ Object
Returns the value of attribute columns.
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#records ⇒ Object
Returns the value of attribute records.
Instance Method Summary collapse
-
#column(label, value = nil, &block) ⇒ Object
field, label: field.to_s.humanize, &block.
- #each {|header| ... } ⇒ Object
-
#initialize(*args, &block) ⇒ StreamContext
constructor
A new instance of StreamContext.
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
#columns ⇒ Object
Returns the value of attribute columns
61 62 63 |
# File 'lib/decisive/template_handler.rb', line 61 def columns @columns end |
#filename ⇒ Object
Returns the value of attribute filename
61 62 63 |
# File 'lib/decisive/template_handler.rb', line 61 def filename @filename end |
#records ⇒ Object
Returns the value of attribute 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
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 |