Module: Origami::StandardObject
- Included in:
- Action, Action::GoToE::EmbeddedTarget, Action::Launch::WindowsLaunchParams, Action::RichMediaExecute::Command, Adobe::PPKLite::AddressList, Adobe::PPKLite::Catalog, Adobe::PPKLite::Certificate, Adobe::PPKLite::PPK, Adobe::PPKLite::User, Adobe::PPKLite::UserList, AnimationStyle3D, Annotation, Annotation::AdditionalActions, Annotation::AppearanceCharacteristics, Annotation::AppearanceDictionary, Annotation::Artwork3D::Activation, 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, CrossSection3D, DeveloperExtension, EmbeddedFileParameters, EmbeddedFileStream, Encoding, Encryption::CryptFilterDictionary, Encryption::EncryptionDictionary, Extensions, 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::Pattern::Shading, Graphics::Pattern::Shading::Axial, Graphics::Pattern::Shading::FunctionBased, Graphics::Pattern::Shading::Radial, Graphics::ReferenceDictionary, InteractiveForm, LightingScheme3D, Linearization, Metadata, MetadataStream, NameTreeNode, Names, NavigationNode, Node3D, Outline, OutlineItem, OutputIntent, Page, PageAdditionalActions, PageTreeNode, Perms, Projection3D, Reference3D, RenderMode3D, Requirement, Requirement::Handler, Resources, Origami::Signature::BuildData, Origami::Signature::BuildProperties, Origami::Signature::DigitalSignature, Origami::Signature::Reference, Stream, Trailer, U3DStream, UsageRights::TransformParams, View3D, ViewerPreferences, 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.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.
-
#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:
107 108 109 110 |
# File 'lib/origami/object.rb', line 107 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:
216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/origami/object.rb', line 216 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.native_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.
177 178 179 |
# File 'lib/origami/object.rb', line 177 def has_field? (field) not self[field].nil? end |
#pdf_version_required ⇒ Object
Returns the version and level required by the current Object.
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/origami/object.rb', line 184 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:
165 166 167 168 169 170 171 |
# File 'lib/origami/object.rb', line 165 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:
203 204 205 206 207 208 |
# File 'lib/origami/object.rb', line 203 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:
210 211 212 213 214 |
# File 'lib/origami/object.rb', line 210 def set_default_values #:nodoc: self.class.required_fields.each do |field| set_default_value(field) unless has_field?(field) end end |