summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRandy Morgan <[email protected]>2012-11-05 14:08:42 +0900
committerRandy Morgan <[email protected]>2012-11-05 14:08:42 +0900
commit8ffd7652c4cc66b52f7992f24a2effc7dc3958c8 (patch)
tree07e8f9684d241db7fe513c2055ca2789df3361f2
parent75eee58d7aecd0f0e89ec7a8ff2a37e6013f9e8d (diff)
downloadcaxlsx-8ffd7652c4cc66b52f7992f24a2effc7dc3958c8.tar.gz
caxlsx-8ffd7652c4cc66b52f7992f24a2effc7dc3958c8.zip
completed documentation
-rw-r--r--lib/axlsx/content_type/abstract_content_type.rb4
-rw-r--r--lib/axlsx/content_type/default.rb2
-rw-r--r--lib/axlsx/content_type/override.rb2
-rw-r--r--lib/axlsx/stylesheet/gradient_fill.rb1
-rw-r--r--lib/axlsx/util/accessors.rb23
-rw-r--r--lib/axlsx/util/options_parser.rb6
-rw-r--r--lib/axlsx/util/serialized_attributes.rb14
-rw-r--r--lib/axlsx/workbook/worksheet/worksheet.rb8
8 files changed, 56 insertions, 4 deletions
diff --git a/lib/axlsx/content_type/abstract_content_type.rb b/lib/axlsx/content_type/abstract_content_type.rb
index ac17dce9..0afaa53f 100644
--- a/lib/axlsx/content_type/abstract_content_type.rb
+++ b/lib/axlsx/content_type/abstract_content_type.rb
@@ -1,9 +1,12 @@
module Axlsx
+ # This class extracts the common parts from Default and Override
class AbstractContentType
include Axlsx::OptionsParser
+ # Initializes an abstract content type
+ # @see Default, Override
def initialize(options={})
parse_options options
end
@@ -18,6 +21,7 @@ module Axlsx
def content_type=(v) Axlsx::validate_content_type v; @content_type = v end
alias :ContentType= :content_type=
+ # Serialize the contenty type to xml
def to_xml_string(node_name = '', str = '')
str << "<#{node_name} "
str << instance_values.map { |key, value| '' << Axlsx::camel(key) << '="' << value.to_s << '"' }.join(' ')
diff --git a/lib/axlsx/content_type/default.rb b/lib/axlsx/content_type/default.rb
index 0cd00d48..3fe15609 100644
--- a/lib/axlsx/content_type/default.rb
+++ b/lib/axlsx/content_type/default.rb
@@ -4,6 +4,7 @@ module Axlsx
# An default content part. These parts are automatically created by for you based on the content of your package.
class Default < AbstractContentType
+ # The serialization node name for this class
NODE_NAME = 'Default'
# The extension of the content type.
@@ -15,6 +16,7 @@ module Axlsx
def extension=(v) Axlsx::validate_string v; @extension = v end
alias :Extension= :extension=
+ # Serializes this object to xml
def to_xml_string(str ='')
super(NODE_NAME, str)
end
diff --git a/lib/axlsx/content_type/override.rb b/lib/axlsx/content_type/override.rb
index 01918321..7a8e33fa 100644
--- a/lib/axlsx/content_type/override.rb
+++ b/lib/axlsx/content_type/override.rb
@@ -5,6 +5,7 @@ module Axlsx
# An override content part. These parts are automatically created by for you based on the content of your package.
class Override < AbstractContentType
+ # Serialization node name for this object
NODE_NAME = 'Override'
# The name and location of the part.
@@ -16,6 +17,7 @@ module Axlsx
def part_name=(v) Axlsx::validate_string v; @part_name = v end
alias :PartName= :part_name=
+ # Serializes this object to xml
def to_xml_string(str = '')
super(NODE_NAME, str)
end
diff --git a/lib/axlsx/stylesheet/gradient_fill.rb b/lib/axlsx/stylesheet/gradient_fill.rb
index cfd51e64..b077d497 100644
--- a/lib/axlsx/stylesheet/gradient_fill.rb
+++ b/lib/axlsx/stylesheet/gradient_fill.rb
@@ -84,6 +84,7 @@ module Axlsx
@bottom = v
end
+ # validates that the value provided is between 0.0 and 1.0
def validate_format_percentage(name, value)
DataTypeValidator.validate name, Float, value, lambda { |arg| arg >= 0.0 && arg <= 1.0}
end
diff --git a/lib/axlsx/util/accessors.rb b/lib/axlsx/util/accessors.rb
index 3096d9c7..f578be26 100644
--- a/lib/axlsx/util/accessors.rb
+++ b/lib/axlsx/util/accessors.rb
@@ -1,19 +1,42 @@
module Axlsx
+ # This module defines some of the more common validating attribute
+ # accessors that we use in Axlsx
+ #
+ # When this module is included in your class you can simply call
+ #
+ # string_attr_access :foo
+ #
+ # To generate a new, validating set of accessors for foo.
module Accessors
def self.included(base)
base.send :extend, ClassMethods
end
+ # Defines the class level xxx_attr_accessor methods
module ClassMethods
+
+ # Creates one or more string validated attr_accessors
+ # @param [Array] symbols An array of symbols representing the
+ # names of the attributes you will add to your class.
def string_attr_accessor(*symbols)
validated_attr_accessor(symbols, 'validate_string')
end
+ # Creates on or more boolean validated attr_accessors
+ # @param [Array] symbols An array of symbols representing the
+ # names of the attributes you will add to your class.
def boolean_attr_accessor(*symbols)
validated_attr_accessor(symbols, 'validate_boolean')
end
+ # Template for defining validated write accessors
SETTER = "def %s=(value) Axlsx::%s(value); @%s = value; end"
+
+ # Creates the reader and writer access methods
+ # @param [Array] symbols The names of the attributes to create
+ # @param [String] validator The axlsx validation method to use when
+ # validating assignation.
+ # @see lib/axlsx/util/validators.rb
def validated_attr_accessor(symbols, validator)
symbols.each do |symbol|
attr_reader symbol
diff --git a/lib/axlsx/util/options_parser.rb b/lib/axlsx/util/options_parser.rb
index b6332275..07dd128b 100644
--- a/lib/axlsx/util/options_parser.rb
+++ b/lib/axlsx/util/options_parser.rb
@@ -1,5 +1,11 @@
module Axlsx
+ # This module defines a single method for parsing options in class
+ # initializers.
module OptionsParser
+
+ # Parses an options hash by calling any defined method by the same
+ # name of the key postfixed with an '='
+ # @param [Hash] options Options to parse.
def parse_options(options={})
options.each do |key, value|
self.send("#{key}=", value) if self.respond_to?("#{key}=") && value != nil
diff --git a/lib/axlsx/util/serialized_attributes.rb b/lib/axlsx/util/serialized_attributes.rb
index 50c8d3ae..bffa0a10 100644
--- a/lib/axlsx/util/serialized_attributes.rb
+++ b/lib/axlsx/util/serialized_attributes.rb
@@ -1,20 +1,34 @@
module Axlsx
+ # This module allows us to define a list of symbols defining which
+ # attributes will be serialized for a class.
module SerializedAttributes
+ # Extend with class methods
def self.included(base)
base.send :extend, ClassMethods
end
+ # class methods applied to all includers
module ClassMethods
+ # This is the method to be used in inheriting classes to specify
+ # which of the instance values are serializable
def serializable_attributes(*symbols)
@xml_attributes = symbols
end
+
+ # a reader for those attributes
def xml_attributes
@xml_attributes
end
end
+ # serializes the instance values of the defining object based on the
+ # list of serializable attributes.
+ # @param [String] str The string instance to append this
+ # serialization to.
+ # @param [Hash] additional_attributes An option key value hash for
+ # defining values that are not serializable attributes list.
def serialized_attributes(str = '', additional_attributes = {})
key_value_pairs = instance_values
key_value_pairs.each do |key, value|
diff --git a/lib/axlsx/workbook/worksheet/worksheet.rb b/lib/axlsx/workbook/worksheet/worksheet.rb
index 6a32e881..2080a7f0 100644
--- a/lib/axlsx/workbook/worksheet/worksheet.rb
+++ b/lib/axlsx/workbook/worksheet/worksheet.rb
@@ -237,7 +237,7 @@ module Axlsx
# Indicates if gridlines should be shown in the sheet.
# This is true by default.
# @return [Boolean]
- # @deprecated Use {SheetView#show_grid_lines=} instead.
+ # @deprecated Use SheetView#show_grid_lines= instead.
def show_gridlines=(v)
warn('axlsx::DEPRECIATED: Worksheet#show_gridlines= has been depreciated. This value can be set over SheetView#show_grid_lines=.')
Axlsx::validate_boolean v
@@ -246,7 +246,7 @@ module Axlsx
# @see selected
# @return [Boolean]
- # @deprecated Use {SheetView#tab_selected=} instead.
+ # @deprecated Use SheetView#tab_selected= instead.
def selected=(v)
warn('axlsx::DEPRECIATED: Worksheet#selected= has been depreciated. This value can be set over SheetView#tab_selected=.')
Axlsx::validate_boolean v
@@ -255,7 +255,7 @@ module Axlsx
# Indicates if the worksheet should show gridlines or not
# @return Boolean
- # @deprecated Use {SheetView#show_grid_lines} instead.
+ # @deprecated Use SheetView#show_grid_lines instead.
def show_gridlines
warn('axlsx::DEPRECIATED: Worksheet#show_gridlines has been depreciated. This value can get over SheetView#show_grid_lines.')
sheet_view.show_grid_lines
@@ -265,7 +265,7 @@ module Axlsx
# It is possible to have more than one worksheet selected, however it might cause issues
# in some older versions of excel when using copy and paste.
# @return Boolean
- # @deprecated Use {SheetView#tab_selected} instead.
+ # @deprecated Use SheetView#tab_selected instead.
def selected
warn('axlsx::DEPRECIATED: Worksheet#selected has been depreciated. This value can get over SheetView#tab_selected.')
sheet_view.tab_selected