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
- #default_options ⇒ 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, .merge() 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
42 43 44 |
# File 'lib/julia/builder.rb', line 42 def self.build(collection, = Hash.new) new(collection, ).build end |
.column(keyname, action = nil, &block) ⇒ Object
18 19 20 |
# File 'lib/julia/builder.rb', line 18 def self.column(keyname, action = nil, &block) columns_config[keyname] = Action.new(keyname, action, &block) end |
.columns(*args) ⇒ Object
22 23 24 25 26 |
# File 'lib/julia/builder.rb', line 22 def self.columns(*args) args.each do |key| column(key) end end |
.columns_config ⇒ Object
28 29 30 |
# File 'lib/julia/builder.rb', line 28 def self.columns_config @columns_config ||= {} end |
Instance Method Details
#build ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/julia/builder.rb', line 32 def build CSV.generate(**) do |csv| collection.each do |record| csv << columns_config.values.map do |action| action.get_value(record, self) end end end end |
#default_options ⇒ Object
11 12 13 14 15 16 |
# File 'lib/julia/builder.rb', line 11 def { headers: columns_config.keys, write_headers: true } end |