Class: When::Parts::Enumerator::Array

Inherits:
When::Parts::Enumerator show all
Defined in:
lib/when_exe/parts/enumerator.rb

Overview

時間位置の Array を順に取り出す Enumerator

Instance Attribute Summary collapse

Attributes inherited from When::Parts::Enumerator

#count, #count_limit, #current, #direction, #exdate, #first, #index, #last, #object, #options, #parent, #processed

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from When::Parts::Enumerator

_options, #each, #has_next?, #next, #succ, #with_index, #with_object

Constructor Details

#initialize(parent, list, count_limit = nil) ⇒ Array

オブジェクトの生成

Parameters:

  • parent (Comparable)

    生成元

  • list (Array<When::TM::TemporalPosition>)

    順に取り出す時間位置の Array

  • direction (Symbol)
    :forward - 昇順
    :reverse - 降順
  • count_limit (Integer) (defaults to: nil)

    繰り返し回数(デフォルトは指定なし)

Raises:

  • (ArgumentError)


376
377
378
379
380
381
# File 'lib/when_exe/parts/enumerator.rb', line 376

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

Instance Attribute Details

#current_listArray

現在リスト

Returns:



353
354
355
# File 'lib/when_exe/parts/enumerator.rb', line 353

def current_list
  @current_list
end

#initial_listArray

初期リスト

Returns:



347
348
349
# File 'lib/when_exe/parts/enumerator.rb', line 347

def initial_list
  @initial_list
end

Class Method Details

._sort(list, direction) ⇒ Object

Note:

eql? はオーバーライドしない

整列して、重複した候補を削除

Parameters:

  • list (Array)
  • direction (Symbol)
    :forward - 昇順
    :reverse - 降順
  • (Array)


329
330
331
332
333
334
335
336
337
338
339
340
341
342
# File 'lib/when_exe/parts/enumerator.rb', line 329

def self._sort(list, direction)
  list = list.sort
  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

Instance Method Details

#_rewindrewind された self

巻き戻す

Returns:



361
362
363
364
# File 'lib/when_exe/parts/enumerator.rb', line 361

def _rewind
  @current_list = @initial_list.dup
  super
end