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.
187 188 189 190 |
# File 'lib/decisive/template_handler.rb', line 187 def initialize *args, &block super instance_eval &block end |
Instance Attribute Details
#columns ⇒ Object
Returns the value of attribute columns
184 185 186 |
# File 'lib/decisive/template_handler.rb', line 184 def columns @columns end |
#filename ⇒ Object
Returns the value of attribute filename
184 185 186 |
# File 'lib/decisive/template_handler.rb', line 184 def filename @filename end |
#records ⇒ Object
Returns the value of attribute 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
209 210 211 |
# File 'lib/decisive/template_handler.rb', line 209 def csv? true end |
#each {|header| ... } ⇒ Object
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 |