Class: Julia::Builder
- Inherits:
-
Object
- Object
- Julia::Builder
- Defined in:
- lib/julia/builder.rb
Instance Attribute Summary collapse
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
-
#csv_options ⇒ Object
readonly
Returns the value of attribute csv_options.
Class Method Summary collapse
- .build(collection, csv_options = Hash.new) ⇒ Object
- .column(keyname, action = nil, &block) ⇒ Object
- .columns ⇒ Object
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(collection, csv_options = Hash.new) ⇒ Builder
constructor
A new instance of Builder.
Constructor Details
#initialize(collection, csv_options = Hash.new) ⇒ Builder
Returns a new instance of Builder.
7 8 9 |
# File 'lib/julia/builder.rb', line 7 def initialize(collection, = Hash.new) @collection, @csv_options = collection, end |
Instance Attribute Details
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
5 6 7 |
# File 'lib/julia/builder.rb', line 5 def collection @collection end |
#csv_options ⇒ Object (readonly)
Returns the value of attribute csv_options.
5 6 7 |
# File 'lib/julia/builder.rb', line 5 def @csv_options end |
Class Method Details
.build(collection, csv_options = Hash.new) ⇒ Object
31 32 33 |
# File 'lib/julia/builder.rb', line 31 def self.build(collection, = Hash.new) new(collection, ).build end |
.column(keyname, action = nil, &block) ⇒ Object
11 12 13 |
# File 'lib/julia/builder.rb', line 11 def self.column(keyname, action = nil, &block) self.columns[keyname] = Action.new(keyname, action, &block) end |
.columns ⇒ Object
15 16 17 |
# File 'lib/julia/builder.rb', line 15 def self.columns @columns ||= {} end |
Instance Method Details
#build ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/julia/builder.rb', line 19 def build CSV.generate() do |csv| csv << columns.keys collection.each do |record| csv << columns.values.map do |action| action.get_value(record) end end end end |