Class: When::Parts::Enumerator::Array
- Inherits:
-
When::Parts::Enumerator
- Object
- Enumerator
- When::Parts::Enumerator
- When::Parts::Enumerator::Array
- Defined in:
- lib/when_exe/parts/enumerator.rb
Overview
時間位置の Array を順に取り出す Enumerator
Instance Attribute Summary
Attributes inherited from When::Parts::Enumerator
#count, #count_limit, #current, #direction, #exdate, #first, #last, #parent, #processed
Class Method Summary collapse
-
._sort(list, direction) ⇒ Array
整列して、重複した候補を削除.
Instance Method Summary collapse
-
#initialize(parent, list, count_limit = nil) ⇒ Array
constructor
オブジェクトの生成.
Methods inherited from When::Parts::Enumerator
#each, #exclude_end, #has_next?, #next, #succ, #with_index, #with_object
Constructor Details
#initialize(parent, list, count_limit = nil) ⇒ Array
オブジェクトの生成
401 402 403 404 405 406 |
# File 'lib/when_exe/parts/enumerator.rb', line 401 def initialize(*args) parent, list, direction, *args = args raise ArgumentError, "Too few arguments" unless list @initial_list = self.class._sort(list, direction||:forward) super(parent, @initial_list[0], direction, *args) end |
Class Method Details
._sort(list, direction) ⇒ Array
Note:
eql? はオーバーライドしない
整列して、重複した候補を削除
354 355 356 357 358 359 360 361 362 363 364 365 366 367 |
# File 'lib/when_exe/parts/enumerator.rb', line 354 def self._sort(list, direction) list = (0...list.size).to_a.map {|i| [list[i], i]}.sort.map {|e| e[0]} prev = nil list.delete_if do |x| if (x == prev) true else prev = x false end end list.reverse! if (direction == :reverse) return list end |