summaryrefslogtreecommitdiffhomepage
path: root/lib/axlsx/workbook/worksheet/protected_range.rb
diff options
context:
space:
mode:
authorRandy Morgan <[email protected]>2012-10-14 13:20:29 +0900
committerRandy Morgan <[email protected]>2012-10-14 13:20:29 +0900
commit25ebea9143c136999bdaeb372fb26d2c070ca730 (patch)
tree0916e207715d821d3f4f8de45c9690ca65272633 /lib/axlsx/workbook/worksheet/protected_range.rb
parent93b70a39999ac4d06e43e495f3fd283e9630d9d2 (diff)
downloadcaxlsx-25ebea9143c136999bdaeb372fb26d2c070ca730.tar.gz
caxlsx-25ebea9143c136999bdaeb372fb26d2c070ca730.zip
Refactored to use options parser, accessors and serialization attributes
Diffstat (limited to 'lib/axlsx/workbook/worksheet/protected_range.rb')
-rw-r--r--lib/axlsx/workbook/worksheet/protected_range.rb28
1 files changed, 16 insertions, 12 deletions
diff --git a/lib/axlsx/workbook/worksheet/protected_range.rb b/lib/axlsx/workbook/worksheet/protected_range.rb
index 5917ad6e..c58b895d 100644
--- a/lib/axlsx/workbook/worksheet/protected_range.rb
+++ b/lib/axlsx/workbook/worksheet/protected_range.rb
@@ -4,6 +4,18 @@ module Axlsx
# @see Worksheet#protect_range
class ProtectedRange
+ include Axlsx::OptionsParser
+ include Axlsx::SerializedAttributes
+
+ # Initializes a new protected range object
+ # @option [String] sqref The cell range reference to protect. This can be an absolute or a relateve range however, it only applies to the current sheet.
+ # @option [String] name An optional name for the protected name.
+ def initialize(options={})
+ parse_options options
+ yield self if block_given?
+ end
+
+ serializable_attributes :sqref, :name
# The reference for the protected range
# @return [String]
attr_reader :sqref
@@ -12,16 +24,6 @@ module Axlsx
# @return [String]
attr_reader :name
- # Initializes a new protected range object
- # @option [String] sqref The cell range reference to protect. This can be an absolute or a relateve range however, it only applies to the current sheet.
- # @option [String] name An optional name for the protected name.
- def initialize(options={})
- options.each do |o|
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
- end
- yield self if block_given?
- end
-
# @see sqref
def sqref=(v)
Axlsx.validate_string(v)
@@ -33,14 +35,16 @@ module Axlsx
Axlsx.validate_string(v)
@name = v
end
-
+
# serializes the proteted range
# @param [String] str if this string object is provided we append
# our output to that object. Use this - it helps limit the number of
# objects created during serialization
def to_xml_string(str="")
attrs = self.instance_values.reject{ |key, value| value == nil }
- str << '<protectedRange ' << attrs.map { |key, value| '' << key << '="' << value.to_s << '"' }.join(' ') << '/>'
+ str << '<protectedRange '
+ serialized_attributes str
+ str << '/>'
end
end
end