Module: Origami::StandardObject
- Included in:
- EmbeddedFileParameters, EmbeddedFileStream, Encryption::CryptFilterDictionary, Encryption::EncryptionDictionary, FileSpec, Filter::CCITTFax::DecodeParms, Filter::Crypt::DecodeParms, Filter::DCT::DecodeParms, Filter::Flate::DecodeParms, Filter::JBIG2::DecodeParms, Filter::LZW::DecodeParms, Graphics::ExtGState, Graphics::Pattern::Shading, Graphics::Pattern::Shading::Axial, Graphics::Pattern::Shading::FunctionBased, Graphics::Pattern::Shading::Radial, Graphics::ReferenceDictionary, Metadata, MetadataStream, NavigationNode, Outline, OutlineItem, OutputIntent, Page, PageAdditionalActions, PageTreeNode, Perms, Resources, Origami::Signature::BuildData, Origami::Signature::BuildProperties, Origami::Signature::DigitalSignature, Origami::Signature::Reference, Stream, Trailer, UsageRights::TransformParams, Webcapture::Command, Webcapture::CommandSettings, Webcapture::SourceInformation, Webcapture::SpiderInfo, XRefStream
- Defined in:
- lib/origami/object.rb
Overview
Mixin’ module for objects which can store their options into an inner Dictionary.
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- DEFAULT_ATTRIBUTES =
:nodoc:
{ :Type => Object, :Version => "1.1" }
Class Method Summary collapse
-
.included(receiver) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#do_type_check ⇒ Object
:nodoc:.
-
#has_field?(field) ⇒ Boolean
Check if an attribute is set in the current Object.
-
#pdf_version_required ⇒ Object
Returns the version and level required by the current Object.
-
#pre_build ⇒ Object
:nodoc:.
-
#set_default_value(field) ⇒ Object
:nodoc:.
-
#set_default_values ⇒ Object
:nodoc:.
Class Method Details
.included(receiver) ⇒ Object
:nodoc:
111 112 113 114 |
# File 'lib/origami/object.rb', line 111 def self.included(receiver) #:nodoc: receiver.instance_variable_set(:@fields, Hash.new(DEFAULT_ATTRIBUTES)) receiver.extend(ClassMethods) end |
Instance Method Details
#do_type_check ⇒ Object
:nodoc:
212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/origami/object.rb', line 212 def do_type_check #:nodoc: self.class.fields.each_pair do |field, attributes| if not self[field].nil? and not attributes[:Type].nil? types = attributes[:Type].is_a?(::Array) ? attributes[:Type] : [ attributes[:Type] ] if not self[field].is_a?(Reference) and types.all? {|type| not self[field].is_a?(type)} puts "Warning: in object #{self.class}, field `#{field.to_s}' has unexpected type #{self[field].class}" end end end end |
#has_field?(field) ⇒ Boolean
Check if an attribute is set in the current Object.
- attr
-
The attribute name.
173 174 175 |
# File 'lib/origami/object.rb', line 173 def has_field? (field) not self[field].nil? end |
#pdf_version_required ⇒ Object
Returns the version and level required by the current Object.
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/origami/object.rb', line 180 def pdf_version_required #:nodoc: max = [ 1.0, 0 ] self.each_key do |field| attributes = self.class.fields[field.value] current_version = attributes.has_key?(:Version) ? attributes[:Version].to_f : 0 current_level = attributes[:ExtensionLevel] || 0 current = [ current_version, current_level ] max = current if (current <=> max) > 0 sub = self[field.value].pdf_version_required max = sub if (sub <=> max) > 0 end max end |
#pre_build ⇒ Object
:nodoc:
161 162 163 164 165 166 167 |
# File 'lib/origami/object.rb', line 161 def pre_build #:nodoc: set_default_values do_type_check if Origami::OPTIONS[:enable_type_checking] == true super end |
#set_default_value(field) ⇒ Object
:nodoc:
199 200 201 202 203 204 |
# File 'lib/origami/object.rb', line 199 def set_default_value(field) #:nodoc: if self.class.fields[field][:Default] self[field] = self.class.fields[field][:Default] self[field].pre_build end end |
#set_default_values ⇒ Object
:nodoc:
206 207 208 209 210 |
# File 'lib/origami/object.rb', line 206 def set_default_values #:nodoc: self.class.required_fields.each do |field| set_default_value(field) unless has_field?(field) end end |