Class: Excelizer::Base
- Inherits:
-
Object
- Object
- Excelizer::Base
- Defined in:
- lib/excelizer/base.rb
Class Attribute Summary collapse
- .instance_method ⇒ Object readonly
Instance Attribute Summary collapse
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
Class Method Summary collapse
- .attribute(name, options = {}) ⇒ Object
- .attributes ⇒ Object
- .headers ⇒ Object
- .instance(instance_method) ⇒ Object
Instance Method Summary collapse
- #download ⇒ Object
-
#initialize(collection = []) ⇒ Base
constructor
A new instance of Base.
- #records ⇒ Object
Constructor Details
#initialize(collection = []) ⇒ Base
Returns a new instance of Base.
6 7 8 |
# File 'lib/excelizer/base.rb', line 6 def initialize(collection = []) self.collection = collection end |
Class Attribute Details
.instance_method ⇒ Object
34 35 36 |
# File 'lib/excelizer/base.rb', line 34 def instance_method @instance_method ||= :object end |
Instance Attribute Details
#collection ⇒ Object
Returns the value of attribute collection.
4 5 6 |
# File 'lib/excelizer/base.rb', line 4 def collection @collection end |
Class Method Details
.attribute(name, options = {}) ⇒ Object
38 39 40 |
# File 'lib/excelizer/base.rb', line 38 def attribute(name, = {}) attributes << Attribute.new(name, ) end |
.attributes ⇒ Object
42 43 44 |
# File 'lib/excelizer/base.rb', line 42 def attributes @attributes ||= [] end |
.headers ⇒ Object
46 47 48 |
# File 'lib/excelizer/base.rb', line 46 def headers attributes.flat_map(&:header) end |
.instance(instance_method) ⇒ Object
29 30 31 32 |
# File 'lib/excelizer/base.rb', line 29 def instance(instance_method) self.instance_method = instance_method define_method(instance_method) { @record } end |
Instance Method Details
#download ⇒ Object
10 11 12 |
# File 'lib/excelizer/base.rb', line 10 def download Excelizer::Writer.write self.class.headers, records end |
#records ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/excelizer/base.rb', line 14 def records collection.map do |item| @record = item self.class.attributes.map do |attribute| method = attribute.name (respond_to?(method) ? send(method) : item.send(method)).to_s end end end |