summaryrefslogtreecommitdiffhomepage
path: root/lib/axlsx/util
diff options
context:
space:
mode:
authorRandy Morgan <[email protected]>2012-09-30 18:29:48 +0900
committerRandy Morgan <[email protected]>2012-09-30 18:29:48 +0900
commite7a2916e33db7582ae8da307692cab6bd21b6bab (patch)
treec5f2d0710747b817e737bbb9811b5a9ef4585f7f /lib/axlsx/util
parenta942008d3b0f4618a3d35541de6f97ad487a463c (diff)
downloadcaxlsx-e7a2916e33db7582ae8da307692cab6bd21b6bab.tar.gz
caxlsx-e7a2916e33db7582ae8da307692cab6bd21b6bab.zip
Forgot to add these files to last commit!
extraction refactoring
Diffstat (limited to 'lib/axlsx/util')
-rw-r--r--lib/axlsx/util/boolean_attributes.rb43
-rw-r--r--lib/axlsx/util/module.rb20
2 files changed, 20 insertions, 43 deletions
diff --git a/lib/axlsx/util/boolean_attributes.rb b/lib/axlsx/util/boolean_attributes.rb
deleted file mode 100644
index 48918b63..00000000
--- a/lib/axlsx/util/boolean_attributes.rb
+++ /dev/null
@@ -1,43 +0,0 @@
-module Axlsx
- module BooleanAttributes
- def BooleanAttributes.included(mod)
- mod::BOOLEAN_ATTRIBUTES.each do |attr|
- class_eval %{
- # The #{attr} attribute reader
- # @return [Boolean]
- attr_reader :#{attr}
-
- # The #{attr} writer
- # @param [Boolean] value The value to assign to #{attr}
- # @return [Boolean]
- def #{attr}=(value)
- Axlsx::validate_boolean(value)
- @#{attr} = value
- end
- }
- end
- end
- end
-
- module StringAttributes
- def StringAttributes.included(mod)
- mod::STRING_ATTRIBUTES.each do |attr|
- class_eval %{
- # The #{attr} attribute reader
- # @return [String]
- attr_reader :#{attr}
-
- # The #{attr} writer
- # @param [String] value The value to assign to #{attr}
- # @return [String]
- def #{attr}=(value)
- Axlsx::validate_string(value)
- @#{attr}= value
- end
- }
-
- end
- end
- end
-
-end
diff --git a/lib/axlsx/util/module.rb b/lib/axlsx/util/module.rb
new file mode 100644
index 00000000..ecc62326
--- /dev/null
+++ b/lib/axlsx/util/module.rb
@@ -0,0 +1,20 @@
+class Module
+ def string_attr_accessor(*symbols)
+ validated_attr_accessor(symbols, 'validate_string')
+ end
+
+ def boolean_attr_accessor(*symbols)
+ validated_attr_accessor(symbols, 'validate_boolean')
+ end
+
+ private
+
+ SETTER = "def %s=(value) Axlsx::%s(value); @%s = value; end"
+ def validated_attr_accessor(symbols, validator)
+ symbols.each do |symbol|
+ attr_reader symbol
+ module_eval(SETTER % [symbol.to_s, validator, symbol.to_s], __FILE__, __LINE__)
+ end
+ end
+
+end