Class: Sevgi::Sundries::Ruler

Inherits:
Interval
  • Object
show all
Defined in:
lib/sevgi/sundries/ruler.rb

Overview

<------------------------ d = n x sd -----------------------------><--- waste = 2 x margin ---> <----- u = unit x multiple -----> <------ sd = su x sn -----> (computed margin >= given margin)

|----------+----------+----------|----------+----------+----------|···························|

<----------------------------------------- brut ---------------------------------------------->

Direct Known Subclasses

Grid::Axis, RulerEven

Instance Attribute Summary collapse

Attributes inherited from Interval

#n, #u

Instance Method Summary collapse

Methods inherited from Interval

[], #[], #count, #d, #ds, #h, #hs, #nds, #nhs

Constructor Details

#initialize(brut:, unit:, multiple:, margin: 0.0) ⇒ Ruler

Returns a new instance of Ruler.



62
63
64
# File 'lib/sevgi/sundries/ruler.rb', line 62

def initialize(brut:, unit:, multiple:, margin: 0.0)
  super(@sub = Interval.new(unit, multiple), divide(unit:, multiple:, brut: (@brut = brut.to_f), margin:))
end

Instance Attribute Details

#brutObject (readonly)

Returns the value of attribute brut.



60
61
62
# File 'lib/sevgi/sundries/ruler.rb', line 60

def brut
  @brut
end

#subObject (readonly)

Returns the value of attribute sub.



60
61
62
# File 'lib/sevgi/sundries/ruler.rb', line 60

def sub
  @sub
end

Instance Method Details

#expandObject



66
# File 'lib/sevgi/sundries/ruler.rb', line 66

def expand = self.class.new(unit: sub.u, multiple: 1, brut: d + waste, margin:)

#marginObject



68
# File 'lib/sevgi/sundries/ruler.rb', line 68

def margin = @margin ||= waste / 2.0

#msObject



70
# File 'lib/sevgi/sundries/ruler.rb', line 70

def ms = @ms ||= expand.ds

#sdObject



76
# File 'lib/sevgi/sundries/ruler.rb', line 76

def sd = @sub.d

#snObject



74
# File 'lib/sevgi/sundries/ruler.rb', line 74

def sn = @sub.n

#suObject



78
# File 'lib/sevgi/sundries/ruler.rb', line 78

def su = @sub.u

#wasteObject



72
# File 'lib/sevgi/sundries/ruler.rb', line 72

def waste = @waste ||= brut - d