Module: Pdfrb::Model::Cos::Fields::DictionaryConverter
- Defined in:
- lib/pdfrb/model/cos/fields.rb
Overview
---- Converter modules ----
Stateless. usable_for?(type) filters; convert(data, type, document) returns the converted value or nil to fall through.
Class Method Summary collapse
- .additional_types ⇒ Object
- .convert(data, type, document) ⇒ Object
- .upgradeable?(data, declared) ⇒ Object
- .usable_for?(type) ⇒ Boolean
Class Method Details
.additional_types ⇒ Object
83 |
# File 'lib/pdfrb/model/cos/fields.rb', line 83 def additional_types; ::Hash; end |
.convert(data, type, document) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/pdfrb/model/cos/fields.rb', line 85 def convert(data, type, document) first = type.first return if first.nil? return if data.is_a?(first) && !upgradeable?(data, first) return unless data.is_a?(::Hash) || data.is_a?(Pdfrb::Model::Cos::Dictionary) # No `type:` — let document#wrap dispatch via /Type so a # field typed as bare Cos::Dictionary still upgrades to a # specific Type::* subclass when the value has a /Type. document&.wrap(data) end |
.upgradeable?(data, declared) ⇒ Object
97 98 99 100 101 102 103 |
# File 'lib/pdfrb/model/cos/fields.rb', line 97 def upgradeable?(data, declared) # Already-typed subclass of declared base — leave alone. return false unless data.is_a?(Pdfrb::Model::Cos::Dictionary) return false if data.class == Pdfrb::Model::Cos::Dictionary data.class <= declared end |
.usable_for?(type) ⇒ Boolean
78 79 80 81 |
# File 'lib/pdfrb/model/cos/fields.rb', line 78 def usable_for?(type) return true if type.is_a?(Symbol) type.is_a?(Class) && type <= Pdfrb::Model::Cos::Dictionary end |