Class: Pdfrb::Model::Cos::Fields::Field
- Inherits:
-
Object
- Object
- Pdfrb::Model::Cos::Fields::Field
- Defined in:
- lib/pdfrb/model/cos/fields.rb
Overview
One declared field on a Dictionary subclass.
Instance Attribute Summary collapse
-
#allowed_values ⇒ Object
readonly
Returns the value of attribute allowed_values.
-
#arlington ⇒ Object
readonly
Returns the value of attribute arlington.
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#indirect ⇒ Object
readonly
Returns the value of attribute indirect.
-
#pdf_name ⇒ Object
readonly
Returns the value of attribute pdf_name.
-
#required ⇒ Object
readonly
Returns the value of attribute required.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #default? ⇒ Boolean
- #has_allowed_values? ⇒ Boolean
-
#initialize(pdf_name, type:, required: false, default: nil, indirect: nil, allowed_values: nil, version: "1.0", arlington: nil) ⇒ Field
constructor
A new instance of Field.
- #required? ⇒ Boolean
-
#resolved_types ⇒ Object
Resolve Symbol types via Dictionary.type_map.
- #valid_value?(value) ⇒ Boolean
Constructor Details
#initialize(pdf_name, type:, required: false, default: nil, indirect: nil, allowed_values: nil, version: "1.0", arlington: nil) ⇒ Field
Returns a new instance of Field.
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/pdfrb/model/cos/fields.rb', line 29 def initialize(pdf_name, type:, required: false, default: nil, indirect: nil, allowed_values: nil, version: "1.0", arlington: nil) @pdf_name = pdf_name @type = [type].flatten.freeze @required = required @default = default @indirect = indirect @allowed_values = allowed_values && [allowed_values].flatten.freeze @version = version @arlington = arlington freeze end |
Instance Attribute Details
#allowed_values ⇒ Object (readonly)
Returns the value of attribute allowed_values.
26 27 28 |
# File 'lib/pdfrb/model/cos/fields.rb', line 26 def allowed_values @allowed_values end |
#arlington ⇒ Object (readonly)
Returns the value of attribute arlington.
26 27 28 |
# File 'lib/pdfrb/model/cos/fields.rb', line 26 def arlington @arlington end |
#default ⇒ Object (readonly)
Returns the value of attribute default.
26 27 28 |
# File 'lib/pdfrb/model/cos/fields.rb', line 26 def default @default end |
#indirect ⇒ Object (readonly)
Returns the value of attribute indirect.
26 27 28 |
# File 'lib/pdfrb/model/cos/fields.rb', line 26 def indirect @indirect end |
#pdf_name ⇒ Object (readonly)
Returns the value of attribute pdf_name.
26 27 28 |
# File 'lib/pdfrb/model/cos/fields.rb', line 26 def pdf_name @pdf_name end |
#required ⇒ Object (readonly)
Returns the value of attribute required.
26 27 28 |
# File 'lib/pdfrb/model/cos/fields.rb', line 26 def required @required end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
26 27 28 |
# File 'lib/pdfrb/model/cos/fields.rb', line 26 def type @type end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
26 27 28 |
# File 'lib/pdfrb/model/cos/fields.rb', line 26 def version @version end |
Instance Method Details
#default? ⇒ Boolean
44 |
# File 'lib/pdfrb/model/cos/fields.rb', line 44 def default?; !@default.nil?; end |
#has_allowed_values? ⇒ Boolean
45 |
# File 'lib/pdfrb/model/cos/fields.rb', line 45 def has_allowed_values?; !@allowed_values.nil?; end |
#required? ⇒ Boolean
43 |
# File 'lib/pdfrb/model/cos/fields.rb', line 43 def required?; !!@required; end |
#resolved_types ⇒ Object
Resolve Symbol types via Dictionary.type_map. Returns an array of Class objects (or empty if no resolution yet).
49 50 51 52 53 54 |
# File 'lib/pdfrb/model/cos/fields.rb', line 49 def resolved_types @type.map do |t| next t unless t.is_a?(Symbol) Pdfrb::Model::Cos::Dictionary.lookup_type(t) end.compact end |
#valid_value?(value) ⇒ Boolean
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/pdfrb/model/cos/fields.rb', line 56 def valid_value?(value) types = resolved_types return true if types.empty? types.any? do |t| case value when Pdfrb::Model::Object t === value.value || value.is_a?(t) else t === value end end end |