Class: When::Parts::Enumerator
- Inherits:
-
Enumerator
- Object
- Enumerator
- When::Parts::Enumerator
- Defined in:
- lib/when_exe/parts/enumerator.rb,
lib/when_exe/parts/enumerator.rb
Overview
本ライブラリ用の Enumerator の雛形
Direct Known Subclasses
CalendarTypes::CalendarNote::Enumerator, Coordinates::Residue::BestRationalApproximations, Coordinates::Residue::Enumerator, Array, Integrated, Resource::Enumerator, TM::Duration::Enumerator, V::Event::Enumerator
Defined Under Namespace
Classes: Array, Integrated
Instance Attribute Summary collapse
-
#count ⇒ Integer
readonly
現在の繰り返し回数.
-
#count_limit ⇒ Integer
readonly
最大繰り返し回数.
-
#current ⇒ Comparable
readonly
現在の要素.
-
#direction ⇒ Symbol
readonly
繰り返し方向.
-
#exdate ⇒ When::Parts::GeometricComplex
readonly
除外要素.
-
#first ⇒ Comparable
readonly
最初の要素.
-
#index ⇒ Integer
readonly
現在のインデックス.
-
#last ⇒ Comparable
readonly
最後の要素.
-
#object ⇒ Comparable
readonly
with_object メソッドで渡すインスタンス.
-
#options ⇒ Hash
readonly
オプション.
-
#parent ⇒ Comparable
readonly
生成元オブジェクト.
-
#processed ⇒ When::Parts::GeometricComplex
readonly
処理済み要素.
Class Method Summary collapse
Instance Method Summary collapse
-
#_rewind ⇒ rewind された self
(also: #rewind)
巻き戻す.
-
#each ⇒ rewind された self
ブロックを評価する.
-
#has_next? ⇒ Boolean
次の要素があるか?.
-
#initialize(parent, range, count_limit = nil) ⇒ Enumerator
constructor
オブジェクトの生成.
-
#next ⇒ Comparable
次の要素を取り出す.
-
#succ ⇒ Comparable
次の要素を取り出す.
-
#with_index(offset = 0, &block) ⇒ When::Parts:Enumerator
index をブロックに渡して評価する.
-
#with_object(object, &block) ⇒ When::Parts:Enumerator
index をブロックに渡して評価する.
Constructor Details
#initialize(parent, range, count_limit = nil) ⇒ Enumerator
オブジェクトの生成
251 252 253 254 255 256 257 258 |
# File 'lib/when_exe/parts/enumerator.rb', line 251 def initialize(*args) @options = self.class.(args) @exdate = @options.delete(:exdate) @exevent = @options.delete(:exevent) @parent, *rest = args _range(rest) _rewind end |
Instance Attribute Details
#count ⇒ Integer (readonly)
現在の繰り返し回数
78 79 80 |
# File 'lib/when_exe/parts/enumerator.rb', line 78 def count @count end |
#count_limit ⇒ Integer (readonly)
最大繰り返し回数
74 75 76 |
# File 'lib/when_exe/parts/enumerator.rb', line 74 def count_limit @count_limit end |
#current ⇒ Comparable
現在の要素
82 83 84 |
# File 'lib/when_exe/parts/enumerator.rb', line 82 def current @current end |
#direction ⇒ Symbol (readonly)
繰り返し方向
70 71 72 |
# File 'lib/when_exe/parts/enumerator.rb', line 70 def direction @direction end |
#exdate ⇒ When::Parts::GeometricComplex
除外要素
48 49 50 |
# File 'lib/when_exe/parts/enumerator.rb', line 48 def exdate @exdate end |
#first ⇒ Comparable
最初の要素
58 59 60 |
# File 'lib/when_exe/parts/enumerator.rb', line 58 def first @first end |
#index ⇒ Integer (readonly)
現在のインデックス
88 89 90 |
# File 'lib/when_exe/parts/enumerator.rb', line 88 def index @index end |
#last ⇒ Comparable
最後の要素
63 64 65 |
# File 'lib/when_exe/parts/enumerator.rb', line 63 def last @last end |
#object ⇒ Comparable
with_object メソッドで渡すインスタンス
93 94 95 |
# File 'lib/when_exe/parts/enumerator.rb', line 93 def object @object end |
#options ⇒ Hash
オプション
43 44 45 |
# File 'lib/when_exe/parts/enumerator.rb', line 43 def @options end |
#parent ⇒ Comparable (readonly)
生成元オブジェクト
38 39 40 |
# File 'lib/when_exe/parts/enumerator.rb', line 38 def parent @parent end |
#processed ⇒ When::Parts::GeometricComplex
処理済み要素
53 54 55 |
# File 'lib/when_exe/parts/enumerator.rb', line 53 def processed @processed end |
Class Method Details
._options(args) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/when_exe/parts/enumerator.rb', line 25 def self.(args) = args[-1].kind_of?(Hash) ? args.pop.dup : {} [:exdate] = case [:exdate] when GeometricComplex ; [:exdate].dup when nil ; GeometricComplex.new() else ; GeometricComplex.new([:exdate]) end return end |
Instance Method Details
#_rewind ⇒ rewind された self Also known as: rewind
巻き戻す
165 166 167 168 169 170 171 |
# File 'lib/when_exe/parts/enumerator.rb', line 165 def _rewind @processed = @exdate.dup @count = 0 @current = :first succ self end |
#each ⇒ rewind された self
ブロックを評価する
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/when_exe/parts/enumerator.rb', line 101 def each return self unless block_given? while (has_next?) do if @index yield(succ, @index) @index += 1 elsif @object yield(succ, @object) else yield(succ) end end @index = @object = nil rewind end |
#has_next? ⇒ Boolean
次の要素があるか?
181 182 183 |
# File 'lib/when_exe/parts/enumerator.rb', line 181 def has_next? return (@current != nil) end |
#next ⇒ Comparable
次の要素を取り出す
191 192 193 194 195 |
# File 'lib/when_exe/parts/enumerator.rb', line 191 def next return succ if has_next? rewind raise StopIteration, "Iteration Stopped" end |
#succ ⇒ Comparable
Note:
次の要素がない場合 rewind や、StopIteration例外発生は行わない
次の要素を取り出す
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/when_exe/parts/enumerator.rb', line 207 def succ value = @current if (@count_limit.kind_of?(Numeric) && @count >= @count_limit) @current = nil else loop do @current = _succ break unless (@current) next if (@current == :next) @current = GeometricComplex.new(@current, @duration) if @duration next if _exclude(@current) case @direction when :reverse next if (@current > @first) @current = nil if (@last && @current < @last) break else next if (@current < @first) @current = nil if (@last && @current > @last) break end end @count += 1 _exclude(@current) if (@current) end return value end |
#with_index(offset = 0, &block) ⇒ When::Parts:Enumerator
index をブロックに渡して評価する
126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/when_exe/parts/enumerator.rb', line 126 def with_index(offset=0, &block) if block_given? @index = offset||@count return each(block) else copy = _copy copy.object = nil copy.index = offset||@count return copy end end |
#with_object(object, &block) ⇒ When::Parts:Enumerator
index をブロックに渡して評価する
147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/when_exe/parts/enumerator.rb', line 147 def with_object(object, &block) if block_given? @object = object each(block) return object else copy = _copy copy.object = object copy.index = nil return copy end end |