Class: Crawdad::Breakpoint

Inherits:
Object
  • Object
show all
Defined in:
lib/crawdad/breakpoint.rb

Overview

A node in the breakpoint list.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(position, line, fitness_class, total_width, total_stretch, total_shrink, total_demerits, ratio, previous) ⇒ Breakpoint

Creates a breakpoint node with the given parameters.



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/crawdad/breakpoint.rb', line 24

def initialize(position, line, fitness_class, total_width, total_stretch,
               total_shrink, total_demerits, ratio, previous)
  @position       = position
  @line           = line
  @fitness_class  = fitness_class
  @total_width    = total_width
  @total_stretch  = total_stretch
  @total_shrink   = total_shrink
  @total_demerits = total_demerits
  @ratio          = ratio
  @previous       = previous
end

Instance Attribute Details

#fitness_classObject (readonly)

Fitness class (0=tight, 1=normal, 2=loose, 3=very loose) of the line ending at this breakpoint.



48
49
50
# File 'lib/crawdad/breakpoint.rb', line 48

def fitness_class
  @fitness_class
end

#lineObject (readonly)

Number of the line ending at this breakpoint.



43
44
45
# File 'lib/crawdad/breakpoint.rb', line 43

def line
  @line
end

#positionObject

Index of this breakpoint within the sequence of items.



39
40
41
# File 'lib/crawdad/breakpoint.rb', line 39

def position
  @position
end

#previousObject (readonly)

Link to the best preceding breakpoint.



74
75
76
# File 'lib/crawdad/breakpoint.rb', line 74

def previous
  @previous
end

#ratioObject (readonly)

The ratio of stretch or shrink used for the line ending at this breakpoint. 0 is a perfect fit; +1 means 100% of the stretch has been used; -1 means all of the shrink has been used.



70
71
72
# File 'lib/crawdad/breakpoint.rb', line 70

def ratio
  @ratio
end

#total_demeritsObject (readonly)

Minimum total demerits up to this breakpoint.



64
65
66
# File 'lib/crawdad/breakpoint.rb', line 64

def total_demerits
  @total_demerits
end

#total_shrinkObject (readonly)

Total shrink up to after(self). Used to calculate adjustment ratios.



60
61
62
# File 'lib/crawdad/breakpoint.rb', line 60

def total_shrink
  @total_shrink
end

#total_stretchObject (readonly)

Total stretch up to after(self). Used to calculate adjustment ratios.



56
57
58
# File 'lib/crawdad/breakpoint.rb', line 56

def total_stretch
  @total_stretch
end

#total_widthObject (readonly)

Total width up to after(self). Used to calculate adjustment ratios.



52
53
54
# File 'lib/crawdad/breakpoint.rb', line 52

def total_width
  @total_width
end

Class Method Details

.starting_nodeObject

Returns the node used for the head of the active list – represents the starting point.



17
18
19
20
# File 'lib/crawdad/breakpoint.rb', line 17

def self.starting_node
  new(position=0, line=0, fitness_class=1, total_width=0, total_stretch=0, 
      total_shrink=0, total_demerits=0, ratio=0.0, previous=nil)
end

Instance Method Details

#inspectObject



76
77
78
# File 'lib/crawdad/breakpoint.rb', line 76

def inspect
  "#<Breakpoint position=#{@position} ratio=#{@ratio}>"
end