Class: Juncture
- Inherits:
-
Object
show all
- Defined in:
- lib/juncture.rb,
lib/juncture/version.rb
Constant Summary
collapse
- VERSION =
"0.2.0".freeze
- DATE =
"2016-12-20".freeze
Instance Method Summary
collapse
Constructor Details
#initialize(*states, **kwargs) ⇒ Juncture
Returns a new instance of Juncture.
2
3
4
5
|
# File 'lib/juncture.rb', line 2
def initialize *states, **kwargs
@states = states
@current_state = kwargs[:default]
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
7
8
9
10
11
12
13
|
# File 'lib/juncture.rb', line 7
def method_missing meth, *args, &block
if @states.respond_to? meth
@states.send meth, *args, &block
else
super
end
end
|
Instance Method Details
#<(value) ⇒ Object
45
46
47
|
# File 'lib/juncture.rb', line 45
def <(value)
index < @states.index(value)
end
|
#<=(value) ⇒ Object
49
50
51
|
# File 'lib/juncture.rb', line 49
def <=(value)
index <= @states.index(value)
end
|
#==(value) ⇒ Object
37
38
39
|
# File 'lib/juncture.rb', line 37
def ==(value)
@current_state == value
end
|
#===(value) ⇒ Object
41
42
43
|
# File 'lib/juncture.rb', line 41
def ===(value)
@current_state === value
end
|
#>(value) ⇒ Object
53
54
55
|
# File 'lib/juncture.rb', line 53
def >(value)
index > @states.index(value)
end
|
#>=(value) ⇒ Object
57
58
59
|
# File 'lib/juncture.rb', line 57
def >=(value)
index >= @states.index(value)
end
|
#inspect ⇒ Object
15
16
17
|
# File 'lib/juncture.rb', line 15
def inspect
"#<Juncture:%s State:%s>" % [(object_id << 1).to_s(16), @current_state]
end
|
#next ⇒ Object
29
30
31
32
33
34
35
|
# File 'lib/juncture.rb', line 29
def next
if index.nil? || @states[index+1].nil?
@current_state = @states[0]
else
@current_state = @states[index+1]
end
end
|
#set(new_state) ⇒ Object
Also known as:
is
23
24
25
26
|
# File 'lib/juncture.rb', line 23
def set(new_state)
raise "UNKNOWN STATE: %s" % new_state unless @states.include? new_state
@current_state = new_state
end
|
#state ⇒ Object
19
20
21
|
# File 'lib/juncture.rb', line 19
def state
@current_state
end
|