summaryrefslogtreecommitdiffhomepage
path: root/lib/axlsx/content_type
diff options
context:
space:
mode:
authorRandy Morgan <[email protected]>2012-07-10 20:03:51 +0900
committerRandy Morgan <[email protected]>2012-07-10 20:03:51 +0900
commit8f0e868940fe7fd56e2c43e2b1102ec1d3e58a0e (patch)
treef1ca3985d454980073aef0aa387626da565946c6 /lib/axlsx/content_type
parentcc4f75ce39528ed90c57208e83e319370408dd12 (diff)
downloadcaxlsx-8f0e868940fe7fd56e2c43e2b1102ec1d3e58a0e.tar.gz
caxlsx-8f0e868940fe7fd56e2c43e2b1102ec1d3e58a0e.zip
code updates for readability.
part of an ongoing effort to make the code more readable code.
Diffstat (limited to 'lib/axlsx/content_type')
-rw-r--r--lib/axlsx/content_type/content_type.rb1
-rw-r--r--lib/axlsx/content_type/default.rb30
2 files changed, 19 insertions, 12 deletions
diff --git a/lib/axlsx/content_type/content_type.rb b/lib/axlsx/content_type/content_type.rb
index 003991c7..6fa6f944 100644
--- a/lib/axlsx/content_type/content_type.rb
+++ b/lib/axlsx/content_type/content_type.rb
@@ -1,5 +1,6 @@
# encoding: UTF-8
module Axlsx
+
require 'axlsx/content_type/default.rb'
require 'axlsx/content_type/override.rb'
diff --git a/lib/axlsx/content_type/default.rb b/lib/axlsx/content_type/default.rb
index 21e89217..8baafb77 100644
--- a/lib/axlsx/content_type/default.rb
+++ b/lib/axlsx/content_type/default.rb
@@ -1,8 +1,22 @@
# encoding: UTF-8
module Axlsx
+
# An default content part. These parts are automatically created by for you based on the content of your package.
class Default
+ #Creates a new Default object
+ # @option options [String] extension
+ # @option options [String] content_type
+ # @raise [ArgumentError] An argument error is raised if both extension and content_type are not specified.
+ def initialize(options={})
+ raise ArgumentError, INVALID_ARGUMENTS unless validate_options(options)
+ options.each do |name, value|
+ self.send("#{name}=", value) if self.respond_to? "#{name}="
+ end
+ end
+
+ INVALID_ARGUMENTS = "extension and content_type are required"
+ #
# The extension of the content type.
# @return [String]
attr_reader :extension
@@ -13,18 +27,6 @@ module Axlsx
attr_reader :content_type
alias :ContentType :content_type
- #Creates a new Default object
- # @option options [String] extension
- # @option options [String] content_type
- # @raise [ArgumentError] An argument error is raised if both extension and content_type are not specified.
- def initialize(options={})
- raise ArgumentError, "extension and content_type are required" unless (options[:Extension] || options[:extension]) && (options[:content_type] || options[:ContentType])
- options.each do |o|
- self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
- end
- end
-
-
# Sets the file extension for this content type.
def extension=(v) Axlsx::validate_string v; @extension = v end
alias :Extension= :extension=
@@ -43,5 +45,9 @@ module Axlsx
str << '/>'
end
+ private
+ def validate_options(options)
+ (options[:Extension] || options[:extension]) && (options[:content_type] || options[:ContentType])
+ end
end
end