Class: Sevgi::Sundries::Interval

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

Overview

<----------------------------------- d = n x u --------------------------------->

<--------------h = d / 2 --------------->

|---------+---------+---------+---------|---------+---------+---------+---------|

      <--- u --->

Direct Known Subclasses

Ruler

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(e, n) ⇒ Interval

Returns a new instance of Interval.



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

def initialize(e, n) = (@u, @n = measure(e), n)

Instance Attribute Details

#nObject (readonly)

Returns the value of attribute n.



17
18
19
# File 'lib/sevgi/sundries/ruler.rb', line 17

def n
  @n
end

#uObject (readonly)

Returns the value of attribute u.



17
18
19
# File 'lib/sevgi/sundries/ruler.rb', line 17

def u
  @u
end

Class Method Details

.[](e, n) ⇒ Object



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

def self.[](e, n) = new(e, n)

Instance Method Details

#[](i) ⇒ Object



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

def [](i) = ds[i]

#count(length) ⇒ Object



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

def count(length) = (d / length.to_f).to_i

#dObject Also known as: length



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

def d = @d ||= n * u

#dsObject



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

def ds = @ds ||= Array.new(n + 1) { |i| i * u }

#hObject



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

def h = @h ||= d / 2.0

#hsObject



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

def hs = @hs ||= Array.new(n) { |i| u * (0.5 + i) }

#ndsObject



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

def nds = @nds ||= ds.size - 1

#nhsObject



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

def nhs = @nhs ||= hs.size - 1