Class: Decisive::StreamCSVContext
- Inherits:
-
Struct
- Object
- Struct
- Decisive::StreamCSVContext
- Defined in:
- lib/decisive/stream_csv_context.rb
Defined Under Namespace
Classes: Column
Instance Attribute Summary collapse
-
#block ⇒ Object
Returns the value of attribute block.
-
#columns ⇒ Object
readonly
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) ⇒ StreamCSVContext
constructor
A new instance of StreamCSVContext.
Constructor Details
#initialize(*args) ⇒ StreamCSVContext
Returns a new instance of StreamCSVContext.
8 9 10 11 12 |
# File 'lib/decisive/stream_csv_context.rb', line 8 def initialize *args super @columns = [] instance_eval &block end |
Instance Attribute Details
#block ⇒ Object
Returns the value of attribute block
5 6 7 |
# File 'lib/decisive/stream_csv_context.rb', line 5 def block @block end |
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
14 15 16 |
# File 'lib/decisive/stream_csv_context.rb', line 14 def columns @columns end |
#filename ⇒ Object
Returns the value of attribute filename
5 6 7 |
# File 'lib/decisive/stream_csv_context.rb', line 5 def filename @filename end |
#records ⇒ Object
Returns the value of attribute records
5 6 7 |
# File 'lib/decisive/stream_csv_context.rb', line 5 def records @records end |
Instance Method Details
#column(label, value = nil, &block) ⇒ Object
field, label: field.to_s.humanize, &block
16 17 18 19 20 |
# File 'lib/decisive/stream_csv_context.rb', line 16 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
33 34 35 |
# File 'lib/decisive/stream_csv_context.rb', line 33 def csv? true end |
#each {|header| ... } ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/decisive/stream_csv_context.rb', line 22 def each yield header records.map do |record| row = columns.map do |column| column.block.call(record).to_s end yield row end end |