summaryrefslogtreecommitdiffhomepage
path: root/lib/axlsx/util/serialized_attributes.rb
diff options
context:
space:
mode:
authorRandy Morgan <[email protected]>2012-10-14 07:53:59 +0900
committerRandy Morgan <[email protected]>2012-10-14 07:53:59 +0900
commit88d8a35b400cd25b0e68edc13519dae5a9c4d4d6 (patch)
tree83ce894c3be77b55174da9dc13478f5c7ecd05dc /lib/axlsx/util/serialized_attributes.rb
parentbe95b7eaa72cd7007bc0fef22d0c3ea4fa3c3553 (diff)
downloadcaxlsx-88d8a35b400cd25b0e68edc13519dae5a9c4d4d6.tar.gz
caxlsx-88d8a35b400cd25b0e68edc13519dae5a9c4d4d6.zip
Extracted attriubte serialization
Diffstat (limited to 'lib/axlsx/util/serialized_attributes.rb')
-rw-r--r--lib/axlsx/util/serialized_attributes.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/axlsx/util/serialized_attributes.rb b/lib/axlsx/util/serialized_attributes.rb
new file mode 100644
index 00000000..84a7733e
--- /dev/null
+++ b/lib/axlsx/util/serialized_attributes.rb
@@ -0,0 +1,24 @@
+module Axlsx
+ module SerializedAttributes
+
+ def self.included(base)
+ base.send :extend, ClassMethods
+ end
+
+ module ClassMethods
+ def serializable_attributes(*symbols)
+ @@serializable_attributes = symbols
+ end
+ end
+
+ def serialized_attributes(str = '')
+ serializable_values = instance_values.select do |key, value|
+ self.class.serializable_attributes.include?(key.to_sym)
+ end
+ serializable_values.each do |key, value|
+ str << "#{Axlsx.camel(key, false)}='#{value}' "
+ end
+ str
+ end
+ end
+end