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)


390
391
392
393
394
395
# File 'lib/when_exe/parts/enumerator.rb', line 390

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:



367
368
369
# File 'lib/when_exe/parts/enumerator.rb', line 367

def current_list
  @current_list
end

#initial_listArray

初期リスト

Returns:



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

def initial_list
  @initial_list
end

Class Method Details

._sort(list, direction) ⇒ Array

Note:

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

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

Parameters:

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

Returns:



343
344
345
346
347
348
349
350
351
352
353
354
355
356
# File 'lib/when_exe/parts/enumerator.rb', line 343

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:



375
376
377
378
# File 'lib/when_exe/parts/enumerator.rb', line 375

def _rewind
  @current_list = @initial_list.dup
  super
end