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, #exclude_end, #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)


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

Instance Attribute Details

#current_listArray

現在リスト

Returns:



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

def current_list
  @current_list
end

#initial_listArray

初期リスト

Returns:



372
373
374
# File 'lib/when_exe/parts/enumerator.rb', line 372

def initial_list
  @initial_list
end

Class Method Details

._sort(list, direction) ⇒ Array

Note:

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

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

Parameters:

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

Returns:



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 = 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:



386
387
388
389
# File 'lib/when_exe/parts/enumerator.rb', line 386

def _rewind
  @current_list = @initial_list.dup
  super
end