Class: When::Events::Range
- Inherits:
-
Range
- Object
- Range
- When::Events::Range
- Defined in:
- lib/when_exe/events.rb
Overview
イベント管理用範囲オブジェクト
Constant Summary collapse
Instance Attribute Summary collapse
-
#original ⇒ String
readonly
オリジナル文字列.
-
#start ⇒ Object
readonly
小さい方の境界.
-
#until ⇒ Object
readonly
大きい方の境界.
Class Method Summary collapse
-
.convert_from(source) ⇒ When::Events::Range
オブジェクトを When::Events::Range 型に変換する.
Instance Method Summary collapse
-
#include(target) ⇒ Array<Object>
含む対象の抽出.
-
#include?(target) ⇒ Boolean
指定オブジェクトが範囲内か?.
-
#initialize(first, last, exclude_end = false) ⇒ Range
constructor
イベント管理用範囲オブジェクトの生成.
-
#is_complex? ⇒ Boolean
範囲の重なりの判断が複雑になるか?.
-
#is_overlaped?(range) ⇒ Boolean
範囲の重なりの判断.
-
#overlaped(target) ⇒ Array<Object>
範囲が重なる対象の抽出.
Constructor Details
#initialize(first, last, exclude_end = false) ⇒ Range
イベント管理用範囲オブジェクトの生成
181 182 183 184 185 186 187 |
# File 'lib/when_exe/events.rb', line 181 def initialize(first, last, exclude_end=false) @start = first @until = last range = [first, last].map {|edge| edge.respond_to?(:first) ? edge.first : edge} rase ArgumentError, "#{range.last} is less than #{range.first}" if range.last < range.first super(range.first, range.last, exclude_end) end |
Instance Attribute Details
#original ⇒ String
オリジナル文字列
44 45 46 |
# File 'lib/when_exe/events.rb', line 44 def original @original end |
#start ⇒ Object (readonly)
小さい方の境界
32 33 34 |
# File 'lib/when_exe/events.rb', line 32 def start @start end |
#until ⇒ Object (readonly)
大きい方の境界
38 39 40 |
# File 'lib/when_exe/events.rb', line 38 def until @until end |
Class Method Details
.convert_from(source) ⇒ When::Events::Range
オブジェクトを When::Events::Range 型に変換する
53 54 55 56 57 58 59 60 |
# File 'lib/when_exe/events.rb', line 53 def self.convert_from(source) case when source.kind_of?(self) ; source when source.respond_to?(:exclude_end?) ; new(source, source.last, source.exclude_end?) when source.respond_to?(:succ) ; new(source, source.succ, true) else raise ArgumentError, "Can't convert #{source} to #{self}" end end |
Instance Method Details
#include(target) ⇒ Array<Object>
含む対象の抽出
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/when_exe/events.rb', line 89 def include(target) return [] if (exclude_end? && @until <= target) || (!exclude_end? && @until < target) case @start when ::Range return @start.include?(target) ? [@start] : [] when Array list = [] @start.each do |range| break if _range_exceeded?(range, target) list << range if _target_included?(range, target) end return list when Enumerator begin list = [] while (range = @start.succ) break if _range_exceeded?(range, target) list << range if _target_included?(range, target) end return list ensure @start._rewind end else return @start <= target ? [@start] : [] end end |
#include?(target) ⇒ Boolean
指定オブジェクトが範囲内か?
79 80 81 |
# File 'lib/when_exe/events.rb', line 79 def include?(target) !include(target).empty? end |
#is_complex? ⇒ Boolean
範囲の重なりの判断が複雑になるか?
66 67 68 69 70 71 |
# File 'lib/when_exe/events.rb', line 66 def is_complex? case @start when Array, Enumerator ; true else ; false end end |
#is_overlaped?(range) ⇒ Boolean
範囲の重なりの判断
128 129 130 |
# File 'lib/when_exe/events.rb', line 128 def is_overlaped?(range) !overlaped(range).empty? end |
#overlaped(target) ⇒ Array<Object>
範囲が重なる対象の抽出
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/when_exe/events.rb', line 139 def overlaped(target) first = target.first last = target.last last = last.respond_to?(:prev) ? last.prev : last - Delta if target.exclude_end? return [] if (exclude_end? && @until <= first) || (!exclude_end? && @until < first) case @start when ::Range return _target_exceeded?(@start, first) || _range_exceeded?(@start, last) ? [] : [@start] when Array list = [] @start.each do |range| break if _range_exceeded?(range, last) list << range unless _target_exceeded?(range, first) end return list when Enumerator begin list = [] while (range = @start.succ) break if _range_exceeded?(range, last) list << range unless _target_exceeded?(range, first) end return list ensure @start._rewind end else return @start <= last ? [@start] : [] end end |