Class: Pdfrb::Arlington::FieldDefinition
- Inherits:
-
Object
- Object
- Pdfrb::Arlington::FieldDefinition
- Defined in:
- lib/pdfrb/arlington/field_definition.rb
Overview
One row in an Arlington TSV (one field in a PDF object type).
The 12 columns are exposed as typed attributes where possible; predicate-laden values (Required, SpecialCase, SinceVersion with fn:...) preserve their raw text for the predicate evaluator to consume lazily.
Instance Attribute Summary collapse
-
#default_value ⇒ Object
readonly
Returns the value of attribute default_value.
-
#deprecated_in ⇒ Object
readonly
Returns the value of attribute deprecated_in.
-
#indirect_reference ⇒ Object
readonly
Returns the value of attribute indirect_reference.
-
#inheritable ⇒ Object
readonly
Returns the value of attribute inheritable.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#link ⇒ Object
readonly
Returns the value of attribute link.
-
#note ⇒ Object
readonly
Returns the value of attribute note.
-
#possible_values ⇒ Object
readonly
Returns the value of attribute possible_values.
-
#required_literal ⇒ Object
readonly
Returns the value of attribute required_literal.
-
#since_version ⇒ Object
readonly
Returns the value of attribute since_version.
-
#special_case ⇒ Object
readonly
Returns the value of attribute special_case.
-
#types_raw ⇒ Object
readonly
Returns the value of attribute types_raw.
Class Method Summary collapse
-
.from_row(row) ⇒ Object
Build a FieldDefinition from a 12-element Array of TSV cells.
Instance Method Summary collapse
- #array? ⇒ Boolean
- #dictionary? ⇒ Boolean
- #inheritable? ⇒ Boolean
-
#initialize(key:, types_raw:, since_version:, deprecated_in:, required_literal:, indirect_reference:, inheritable:, default_value:, possible_values:, special_case:, link:, note:) ⇒ FieldDefinition
constructor
A new instance of FieldDefinition.
- #links ⇒ Object
- #name? ⇒ Boolean
- #possible_value_list ⇒ Object
- #required? ⇒ Boolean
- #required_predicate? ⇒ Boolean
- #stream? ⇒ Boolean
-
#types ⇒ Object
The bare type symbols this field allows (predicate-laden types are dropped — caller resolves those via the predicate evaluator if needed).
Constructor Details
#initialize(key:, types_raw:, since_version:, deprecated_in:, required_literal:, indirect_reference:, inheritable:, default_value:, possible_values:, special_case:, link:, note:) ⇒ FieldDefinition
Returns a new instance of FieldDefinition.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/pdfrb/arlington/field_definition.rb', line 17 def initialize(key:, types_raw:, since_version:, deprecated_in:, required_literal:, indirect_reference:, inheritable:, default_value:, possible_values:, special_case:, link:, note:) @key = key @types_raw = types_raw @since_version = since_version @deprecated_in = deprecated_in @required_literal = required_literal @indirect_reference = indirect_reference @inheritable = inheritable @default_value = default_value @possible_values = possible_values @special_case = special_case @link = link @note = note freeze end |
Instance Attribute Details
#default_value ⇒ Object (readonly)
Returns the value of attribute default_value.
12 13 14 |
# File 'lib/pdfrb/arlington/field_definition.rb', line 12 def default_value @default_value end |
#deprecated_in ⇒ Object (readonly)
Returns the value of attribute deprecated_in.
12 13 14 |
# File 'lib/pdfrb/arlington/field_definition.rb', line 12 def deprecated_in @deprecated_in end |
#indirect_reference ⇒ Object (readonly)
Returns the value of attribute indirect_reference.
12 13 14 |
# File 'lib/pdfrb/arlington/field_definition.rb', line 12 def indirect_reference @indirect_reference end |
#inheritable ⇒ Object (readonly)
Returns the value of attribute inheritable.
12 13 14 |
# File 'lib/pdfrb/arlington/field_definition.rb', line 12 def inheritable @inheritable end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
12 13 14 |
# File 'lib/pdfrb/arlington/field_definition.rb', line 12 def key @key end |
#link ⇒ Object (readonly)
Returns the value of attribute link.
12 13 14 |
# File 'lib/pdfrb/arlington/field_definition.rb', line 12 def link @link end |
#note ⇒ Object (readonly)
Returns the value of attribute note.
12 13 14 |
# File 'lib/pdfrb/arlington/field_definition.rb', line 12 def note @note end |
#possible_values ⇒ Object (readonly)
Returns the value of attribute possible_values.
12 13 14 |
# File 'lib/pdfrb/arlington/field_definition.rb', line 12 def possible_values @possible_values end |
#required_literal ⇒ Object (readonly)
Returns the value of attribute required_literal.
12 13 14 |
# File 'lib/pdfrb/arlington/field_definition.rb', line 12 def required_literal @required_literal end |
#since_version ⇒ Object (readonly)
Returns the value of attribute since_version.
12 13 14 |
# File 'lib/pdfrb/arlington/field_definition.rb', line 12 def since_version @since_version end |
#special_case ⇒ Object (readonly)
Returns the value of attribute special_case.
12 13 14 |
# File 'lib/pdfrb/arlington/field_definition.rb', line 12 def special_case @special_case end |
#types_raw ⇒ Object (readonly)
Returns the value of attribute types_raw.
12 13 14 |
# File 'lib/pdfrb/arlington/field_definition.rb', line 12 def types_raw @types_raw end |
Class Method Details
.from_row(row) ⇒ Object
Build a FieldDefinition from a 12-element Array of TSV cells.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/pdfrb/arlington/field_definition.rb', line 37 def self.from_row(row) raise ArgumentError, "TSV row needs 12 cells" unless row.length == 12 new( key: row[0], types_raw: row[1], since_version: PdfVersion.from_tsv_cell(row[2]) || PdfVersion.new("1.0"), deprecated_in: PdfVersion.from_tsv_cell(row[3]), required_literal: parse_required(row[4]), indirect_reference: row[5], inheritable: parse_boolean(row[6]), default_value: row[7]&.then { |s| s.empty? ? nil : s }, possible_values: row[8]&.then { |s| s.empty? ? nil : s }, special_case: row[9]&.then { |s| s.empty? ? nil : s }, link: row[10]&.then { |s| s.empty? ? nil : s }, note: row[11] ) end |
Instance Method Details
#array? ⇒ Boolean
66 67 68 |
# File 'lib/pdfrb/arlington/field_definition.rb', line 66 def array? types.include?(:array) end |
#dictionary? ⇒ Boolean
70 71 72 |
# File 'lib/pdfrb/arlington/field_definition.rb', line 70 def dictionary? types.include?(:dictionary) end |
#inheritable? ⇒ Boolean
90 91 92 |
# File 'lib/pdfrb/arlington/field_definition.rb', line 90 def inheritable? inheritable == true end |
#links ⇒ Object
94 95 96 97 98 |
# File 'lib/pdfrb/arlington/field_definition.rb', line 94 def links return [] if link.nil? link.scan(/\[([^\[\]]+)\]/).flatten.map { |l| l.split(",").map(&:strip) }.flatten end |
#name? ⇒ Boolean
78 79 80 |
# File 'lib/pdfrb/arlington/field_definition.rb', line 78 def name? types.include?(:name) end |
#possible_value_list ⇒ Object
100 101 102 103 104 105 106 |
# File 'lib/pdfrb/arlington/field_definition.rb', line 100 def possible_value_list return [] if possible_values.nil? possible_values.scan(/\[([^\[\]]+)\]/).flatten.flat_map do |l| l.split(",").map(&:strip) end end |
#required? ⇒ Boolean
82 83 84 |
# File 'lib/pdfrb/arlington/field_definition.rb', line 82 def required? required_literal == true end |
#required_predicate? ⇒ Boolean
86 87 88 |
# File 'lib/pdfrb/arlington/field_definition.rb', line 86 def required_predicate? required_literal.is_a?(::String) && required_literal.start_with?("fn:") end |
#stream? ⇒ Boolean
74 75 76 |
# File 'lib/pdfrb/arlington/field_definition.rb', line 74 def stream? types.include?(:stream) end |
#types ⇒ Object
The bare type symbols this field allows (predicate-laden types are dropped — caller resolves those via the predicate evaluator if needed).
59 60 61 62 63 64 |
# File 'lib/pdfrb/arlington/field_definition.rb', line 59 def types types_raw.split(";").filter_map do |raw| stripped = raw.strip stripped.to_sym if Type.valid?(stripped.to_sym) end end |