Class: Diagrams::Spring

Inherits:
Object show all
Defined in:
lib/maruku/ext/diagrams/structures.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(min, shrink, pref, stretch, max) ⇒ Spring

Returns a new instance of Spring.



13
14
15
16
# File 'lib/maruku/ext/diagrams/structures.rb', line 13

def initialize(min,shrink,pref,stretch,max)
	@min,@shrink,@pref,@stretch,@max = 
	 min, shrink, pref, stretch, max
end

Instance Attribute Details

#imposedObject

Returns the value of attribute imposed.



11
12
13
# File 'lib/maruku/ext/diagrams/structures.rb', line 11

def imposed
  @imposed
end

#maxObject

Returns the value of attribute max.



9
10
11
# File 'lib/maruku/ext/diagrams/structures.rb', line 9

def max
  @max
end

#minObject

Returns the value of attribute min.



9
10
11
# File 'lib/maruku/ext/diagrams/structures.rb', line 9

def min
  @min
end

#prefObject

Returns the value of attribute pref.



9
10
11
# File 'lib/maruku/ext/diagrams/structures.rb', line 9

def pref
  @pref
end

#shrinkObject

Returns the value of attribute shrink.



9
10
11
# File 'lib/maruku/ext/diagrams/structures.rb', line 9

def shrink
  @shrink
end

#stretchObject

Returns the value of attribute stretch.



9
10
11
# File 'lib/maruku/ext/diagrams/structures.rb', line 9

def stretch
  @stretch
end

#weightObject

not used yet



10
11
12
# File 'lib/maruku/ext/diagrams/structures.rb', line 10

def weight
  @weight
end

Class Method Details

.parallel(s1, s2) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/maruku/ext/diagrams/structures.rb', line 28

def Spring.parallel(s1,s2)
	pref = (s1.pref+s2.pref)*0.5
	pref = [s1.min, pref].max
	pref = [s1.max, pref].min
	pref = [s2.min, pref].max
	pref = [s2.max, pref].min
	
	Spring.new( 
		[s1.min,s2.min].max, 
		[s1.shrink,s2.shrink].min,
		pref,
		[s1.stretch,s2.stretch].min,
		[s1.max,s2.max].min
		)
end

.series(s1, s2) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/maruku/ext/diagrams/structures.rb', line 18

def Spring.series(s1,s2)
	Spring.new( 
		s1.min+s2.min, 
		s1.shrink+s2.shrink,
		s1.pref+s2.pref,
		s1.stretch+s2.stretch,
		s1.max+s2.max
		)
end

Instance Method Details

#inspectObject



45
46
47
48
49
50
51
52
# File 'lib/maruku/ext/diagrams/structures.rb', line 45

def inspect
	if @min == @max
		"Fixed(#{@min})"
	else
		"S[%.1f(%.1f)%.1f(%.1f)%.1f]=%.1f" %
		[ @min, @shrink, @pref, @stretch, @max, @imposed || -1]
	end
end