Class: Smuggle::Exporter::Base
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Smuggle::Exporter::Base
- Defined in:
- lib/smuggle/exporter/base.rb
Direct Known Subclasses
Class Attribute Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
Class Attribute Details
.attribute_labels(labels) ⇒ Object
23 24 25 |
# File 'lib/smuggle/exporter/base.rb', line 23 def attribute_labels(labels) @attribute_labels.merge!(labels) end |
.attributes(*names) ⇒ Object
15 16 17 |
# File 'lib/smuggle/exporter/base.rb', line 15 def attributes(*names) @attributes.concat names end |
Class Method Details
.attribute_labels? ⇒ Boolean
27 28 29 |
# File 'lib/smuggle/exporter/base.rb', line 27 def attribute_labels? @attribute_labels.any? end |
.attributes? ⇒ Boolean
19 20 21 |
# File 'lib/smuggle/exporter/base.rb', line 19 def attributes? @attributes.any? end |
.header ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/smuggle/exporter/base.rb', line 31 def header return @attributes unless attribute_labels? @attributes.map do |attribute| @attribute_labels.fetch(attribute, attribute) end end |
.inherited(base) ⇒ Object
10 11 12 13 |
# File 'lib/smuggle/exporter/base.rb', line 10 def inherited(base) base.attributes = [] base.attribute_labels = {} end |
Instance Method Details
#defined_attributes ⇒ Object
46 47 48 49 50 51 |
# File 'lib/smuggle/exporter/base.rb', line 46 def defined_attributes return self.class.attributes if self.class.attributes? return attribute_names if __getobj__.respond_to?(:attribute_names) keys if __getobj__.respond_to?(:keys) end |
#to_csv ⇒ Object
40 41 42 43 44 |
# File 'lib/smuggle/exporter/base.rb', line 40 def to_csv defined_attributes.map do |name| respond_to?(name) ? public_send(name) : __getobj__[name] end end |