Class: Steppe::StatusMap
- Inherits:
-
Object
- Object
- Steppe::StatusMap
- Defined in:
- lib/steppe/status_map.rb
Instance Method Summary collapse
- #<<(responder) ⇒ Object
- #each(&block) ⇒ Object
- #find(status) ⇒ Object
-
#initialize ⇒ StatusMap
constructor
A new instance of StatusMap.
Constructor Details
#initialize ⇒ StatusMap
Returns a new instance of StatusMap.
5 6 7 8 |
# File 'lib/steppe/status_map.rb', line 5 def initialize @responders = [] @index = nil end |
Instance Method Details
#<<(responder) ⇒ Object
10 11 12 13 14 |
# File 'lib/steppe/status_map.rb', line 10 def <<(responder) @responders << responder build_index self end |
#each(&block) ⇒ Object
16 17 18 19 20 |
# File 'lib/steppe/status_map.rb', line 16 def each(&block) return enum_for(:each) unless block @responders.each(&block) end |
#find(status) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/steppe/status_map.rb', line 22 def find(status) lo = 0 hi = @index.size - 1 while lo <= hi mid = (lo + hi) / 2 start, finish, responder = @index[mid] if status < start hi = mid - 1 elsif status > finish lo = mid + 1 else return responder end end nil end |