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.
- #csv? ⇒ Boolean
- #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.
123 124 125 126 |
# File 'lib/decisive/template_handler.rb', line 123 def initialize *args, &block super instance_eval &block end |
Instance Attribute Details
#columns ⇒ Object
Returns the value of attribute columns
120 121 122 |
# File 'lib/decisive/template_handler.rb', line 120 def columns @columns end |
#filename ⇒ Object
Returns the value of attribute filename
120 121 122 |
# File 'lib/decisive/template_handler.rb', line 120 def filename @filename end |
#records ⇒ Object
Returns the value of attribute records
120 121 122 |
# File 'lib/decisive/template_handler.rb', line 120 def records @records end |
Instance Method Details
#column(label, value = nil, &block) ⇒ Object
field, label: field.to_s.humanize, &block
128 129 130 131 132 |
# File 'lib/decisive/template_handler.rb', line 128 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
145 146 147 |
# File 'lib/decisive/template_handler.rb', line 145 def csv? true end |
#each {|header| ... } ⇒ Object
134 135 136 137 138 139 140 141 142 143 |
# File 'lib/decisive/template_handler.rb', line 134 def each yield header records.map do |record| row = columns.map do |column| column.block.call(record).to_s end yield row end end |