Class: Uniword::LineNumbering

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

Overview

Represents line numbering configuration for a section

Line numbering displays line numbers in the margin of a document section. It’s commonly used in legal documents and academic papers.

Examples:

Continuous line numbering

ln = LineNumbering.new(
  start: 1,
  count_by: 1,
  restart: 'continuous'
)

Line numbering restarting on each page

ln = LineNumbering.new(
  count_by: 5,
  restart: 'newPage',
  distance: 360
)

Constant Summary collapse

RESTART_OPTIONS =

Restart options

%w[continuous newPage newSection].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**attributes) ⇒ LineNumbering

Returns a new instance of LineNumbering.



38
39
40
41
42
43
# File 'lib/uniword/line_numbering.rb', line 38

def initialize(**attributes)
  super
  validate_restart
  validate_start
  validate_count_by
end

Instance Attribute Details

#count_byInteger

Increment for numbering (e.g., 5 = 5, 10, 15…)

Returns:

  • (Integer)

    the current value of count_by



29
30
31
# File 'lib/uniword/line_numbering.rb', line 29

def count_by
  @count_by
end

#distanceInteger

Distance from text in twips

Returns:

  • (Integer)

    the current value of distance



29
30
31
# File 'lib/uniword/line_numbering.rb', line 29

def distance
  @distance
end

#restartString

When to restart numbering

Returns:

  • (String)

    the current value of restart



29
30
31
# File 'lib/uniword/line_numbering.rb', line 29

def restart
  @restart
end

#startInteger

Starting line number

Returns:

  • (Integer)

    the current value of start



29
30
31
# File 'lib/uniword/line_numbering.rb', line 29

def start
  @start
end

Class Method Details

.continuous(count_by: 1, distance: 360) ⇒ LineNumbering

Create continuous line numbering (never restarts)

Parameters:

  • count_by (Integer) (defaults to: 1)

    Increment

  • distance (Integer) (defaults to: 360)

    Distance from text

Returns:



50
51
52
53
54
55
56
57
# File 'lib/uniword/line_numbering.rb', line 50

def self.continuous(count_by: 1, distance: 360)
  new(
    start: 1,
    count_by: count_by,
    restart: "continuous",
    distance: distance,
  )
end

.per_page(count_by: 1, distance: 360) ⇒ LineNumbering

Create line numbering that restarts on each page

Parameters:

  • count_by (Integer) (defaults to: 1)

    Increment

  • distance (Integer) (defaults to: 360)

    Distance from text

Returns:



64
65
66
67
68
69
70
71
# File 'lib/uniword/line_numbering.rb', line 64

def self.per_page(count_by: 1, distance: 360)
  new(
    start: 1,
    count_by: count_by,
    restart: "newPage",
    distance: distance,
  )
end

.per_section(count_by: 1, distance: 360) ⇒ LineNumbering

Create line numbering that restarts on each section

Parameters:

  • count_by (Integer) (defaults to: 1)

    Increment

  • distance (Integer) (defaults to: 360)

    Distance from text

Returns:



78
79
80
81
82
83
84
85
# File 'lib/uniword/line_numbering.rb', line 78

def self.per_section(count_by: 1, distance: 360)
  new(
    start: 1,
    count_by: count_by,
    restart: "newSection",
    distance: distance,
  )
end

Instance Method Details

#continuous?Boolean

Check if numbering is continuous (never restarts)

Returns:

  • (Boolean)

    true if continuous



90
91
92
# File 'lib/uniword/line_numbering.rb', line 90

def continuous?
  restart == "continuous"
end

#per_page?Boolean

Check if numbering restarts on each page

Returns:

  • (Boolean)

    true if per page



97
98
99
# File 'lib/uniword/line_numbering.rb', line 97

def per_page?
  restart == "newPage"
end

#per_section?Boolean

Check if numbering restarts on each section

Returns:

  • (Boolean)

    true if per section



104
105
106
# File 'lib/uniword/line_numbering.rb', line 104

def per_section?
  restart == "newSection"
end