Class: Uniword::Field

Inherits:
Lutaml::Model::Serializable
  • Object
show all
Defined in:
lib/uniword/field.rb

Overview

Represents a field (dynamic content like page numbers, dates, etc.) Fields can be simple or complex

Constant Summary collapse

TYPES =

Common field types

{
  page: "PAGE",
  numpages: "NUMPAGES",
  date: "DATE",
  time: "TIME",
  seq: "SEQ",
  ref: "REF",
  hyperlink: "HYPERLINK",
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.caption(label: "Figure", format: "ARABIC") ⇒ Object

Create a caption field



62
63
64
# File 'lib/uniword/field.rb', line 62

def self.caption(label: "Figure", format: "ARABIC")
  sequence(label, format: format)
end

.date(format: "M/d/yyyy") ⇒ Object

Create a date field



44
45
46
47
48
49
50
# File 'lib/uniword/field.rb', line 44

def self.date(format: "M/d/yyyy")
  new(
    type: "DATE",
    instruction: " DATE \\@ \"#{format}\" ",
    simple: true,
  )
end

.page_number(format: "ARABIC") ⇒ Object

Create a page number field



26
27
28
29
30
31
32
# File 'lib/uniword/field.rb', line 26

def self.page_number(format: "ARABIC")
  new(
    type: "PAGE",
    instruction: " PAGE \\* #{format} ",
    simple: true,
  )
end

.sequence(label, format: "ARABIC") ⇒ Object

Create a sequence field (for captions)



53
54
55
56
57
58
59
# File 'lib/uniword/field.rb', line 53

def self.sequence(label, format: "ARABIC")
  new(
    type: "SEQ",
    instruction: " SEQ #{label} \\* #{format} ",
    simple: false,
  )
end

.total_pages(format: "ARABIC") ⇒ Object

Create a total pages field



35
36
37
38
39
40
41
# File 'lib/uniword/field.rb', line 35

def self.total_pages(format: "ARABIC")
  new(
    type: "NUMPAGES",
    instruction: " NUMPAGES \\* #{format} ",
    simple: true,
  )
end

Instance Method Details

#complex?Boolean

Check if this is a complex field

Returns:

  • (Boolean)


72
73
74
# File 'lib/uniword/field.rb', line 72

def complex?
  !simple
end

#simple?Boolean

Check if this is a simple field

Returns:

  • (Boolean)


67
68
69
# File 'lib/uniword/field.rb', line 67

def simple?
  simple
end