Module: Origami::StandardObject
- Included in:
- Action, Action::GoToE::EmbeddedTarget, Action::Launch::WindowsLaunchParams, Action::RichMediaExecute::Command, AnimationStyle3D, Annotation, Annotation::AdditionalActions, Annotation::AppearanceCharacteristics, Annotation::AppearanceDictionary, Annotation::Artwork3D::Activation, Annotation::BorderEffect, Annotation::BorderStyle, Annotation::RichMedia::Activation, Annotation::RichMedia::Animation, Annotation::RichMedia::Configuration, Annotation::RichMedia::Content, Annotation::RichMedia::CuePoint, Annotation::RichMedia::Deactivation, Annotation::RichMedia::Instance, Annotation::RichMedia::Parameters, Annotation::RichMedia::Position, Annotation::RichMedia::Presentation, Annotation::RichMedia::Settings, Annotation::RichMedia::Window, Background3D, Catalog, CatalogAdditionalActions, Collection, Collection::Color, Collection::Folder, Collection::Item, Collection::Navigator, Collection::Schema, Collection::Sort, Collection::Split, Collection::Subitem, CrossSection3D, DestinationDictionary, DeveloperExtension, EmbeddedFileParameters, EmbeddedFileStream, Encoding, Encryption::CryptFilterDictionary, Encryption::EncryptionDictionary, Extensions, FDF::Catalog, FDF::Dictionary, FDF::Field, FDF::IconFit, FDF::JavaScript, FDF::NamedPageReference, FDF::Page, FDF::Template, Field::AdditionalActions, Field::CertificateSeedValue, Field::SignatureLock, Field::SignatureSeedValue, Field::Subform, FileSpec, Filter::CCITTFax::DecodeParms, Filter::Crypt::DecodeParms, Filter::DCT::DecodeParms, Filter::Flate::DecodeParms, Filter::JBIG2::DecodeParms, Filter::LZW::DecodeParms, Font, FontDescriptor, Function::Exponential, Function::Stitching, Graphics::ExtGState, Graphics::FormXObject::Group, Graphics::FormXObject::Reference, Graphics::Pattern::Shading, Graphics::Pattern::Shading::Axial, Graphics::Pattern::Shading::FunctionBased, Graphics::Pattern::Shading::Radial, Graphics::ReferenceDictionary, InteractiveForm, LightingScheme3D, Linearization, Measurement3D, Metadata, MetadataStream, NameTreeNode, Names, Node3D, NumberTreeNode, Outline, OutlineItem, OutputIntent, PPKLite::AddressList, PPKLite::Catalog, PPKLite::Certificate, PPKLite::PPK, PPKLite::User, PPKLite::UserList, Page, Page::AdditionalActions, Page::BoxColorInformation, Page::BoxStyle, Page::NavigationNode, PageLabel, PageTreeNode, Perms, Projection3D, Reference3D, RenderMode3D, Requirement, Requirement::Handler, Resources, Origami::Signature::BuildData, Origami::Signature::BuildProperties, Origami::Signature::DigitalSignature, Origami::Signature::Reference, Stream, Trailer, U3DStream, Units3D, UsageRights::TransformParams, View3D, ViewerPreferences, WebCapture::Command, WebCapture::CommandSettings, WebCapture::ContentSet, 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.2" }
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.
-
#pre_build ⇒ Object
:nodoc:.
-
#set_default_value(field) ⇒ Object
:nodoc:.
-
#set_default_values ⇒ Object
:nodoc:.
-
#version_required ⇒ Object
Returns the version and level required by the current Object.
Class Method Details
.included(receiver) ⇒ Object
:nodoc:
102 103 104 105 |
# File 'lib/origami/object.rb', line 102 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:
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 |
# File 'lib/origami/object.rb', line 234 def do_type_check #:nodoc: self.class.fields.each_pair do |field, attributes| next if self[field].nil? or attributes[:Type].nil? begin field_value = self[field].solve rescue InvalidReferenceError STDERR.puts "Warning: in object #{self.class}, field `#{field.to_s}' is an invalid reference (#{self[field].to_s})" next end types = attributes[:Type].is_a?(::Array) ? attributes[:Type] : [ attributes[:Type] ] unless types.any? {|type| not type.is_a?(Class) or field_value.is_a?(type.native_type)} STDERR.puts "Warning: in object #{self.class}, field `#{field.to_s}' has unexpected type #{field_value.class}" end if attributes.key?(:Assert) and not (attributes[:Assert] === field_value) STDERR.puts "Warning: assertion failed for field `#{field.to_s}' in object #{self.class}" end end end |
#has_field?(field) ⇒ Boolean
Check if an attribute is set in the current Object.
- attr
-
The attribute name.
191 192 193 |
# File 'lib/origami/object.rb', line 191 def has_field? (field) not self[field].nil? end |
#pre_build ⇒ Object
:nodoc:
180 181 182 183 184 185 |
# File 'lib/origami/object.rb', line 180 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:
221 222 223 224 225 226 |
# File 'lib/origami/object.rb', line 221 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:
228 229 230 231 232 |
# File 'lib/origami/object.rb', line 228 def set_default_values #:nodoc: self.class.required_fields.each do |field| set_default_value(field) unless has_field?(field) end end |
#version_required ⇒ Object
Returns the version and level required by the current Object.
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/origami/object.rb', line 198 def version_required #:nodoc: max = [ 1.0, 0 ] self.each_key do |field| attributes = self.class.fields[field.value] if attributes.nil? STDERR.puts "Warning: object #{self.class} has undocumented field #{field.value}" next end 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].version_required max = sub if (sub <=> max) > 0 end max end |