class Excelizer::Base
Attributes
instance_method[W]
collection[RW]
Public Class Methods
new(collection = [])
click to toggle source
# File lib/excelizer/base.rb, line 6 def initialize(collection = []) self.collection = collection end
Private Class Methods
attribute(name, options = {})
click to toggle source
# File lib/excelizer/base.rb, line 38 def attribute(name, options = {}) attributes << Attribute.new(name, options) end
attributes()
click to toggle source
# File lib/excelizer/base.rb, line 42 def attributes @attributes ||= [] end
headers()
click to toggle source
# File lib/excelizer/base.rb, line 46 def headers attributes.flat_map(&:header) end
instance(instance_method)
click to toggle source
# File lib/excelizer/base.rb, line 29 def instance(instance_method) self.instance_method = instance_method define_method(instance_method) { @record } end
instance_method()
click to toggle source
# File lib/excelizer/base.rb, line 34 def instance_method @instance_method ||= :object end
Public Instance Methods
download()
click to toggle source
# File lib/excelizer/base.rb, line 10 def download Excelizer::Writer.write self.class.headers, records end
records()
click to toggle source
# 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