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(*args) ⇒ Object
- .columns_config ⇒ 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, = 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 end |
Class Method Details
.build(collection, csv_options = Hash.new) ⇒ Object
37 38 39 |
# File 'lib/julia/builder.rb', line 37 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) columns_config[keyname] = Action.new(keyname, action, &block) end |
.columns(*args) ⇒ Object
15 16 17 18 19 |
# File 'lib/julia/builder.rb', line 15 def self.columns(*args) args.each do |key| column(key) end end |
.columns_config ⇒ Object
21 22 23 |
# File 'lib/julia/builder.rb', line 21 def self.columns_config @columns_config ||= {} end |
Instance Method Details
#build ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/julia/builder.rb', line 25 def build CSV.generate() do |csv| csv << columns_config.keys collection.each do |record| csv << columns_config.values.map do |action| action.get_value(record) end end end end |