Class: When::Coordinates::Residue::Enumerator

Inherits:
Parts::Enumerator show all
Defined in:
lib/when_exe/coordinates.rb

Overview

指定の剰余となる通日or通年を生成する Enumerator

Instance Attribute Summary

Attributes inherited from Parts::Enumerator

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

Instance Method Summary collapse

Methods inherited from Parts::Enumerator

_options, #_rewind, #each, #exclude_end, #has_next?, #next, #with_index, #with_object

Constructor Details

#initialize(parent, range, count_limit = nil) ⇒ Enumerator #initialize(parent, first, direction, count_limit) ⇒ Enumerator

オブジェクトの生成

Overloads:

  • #initialize(parent, range, count_limit = nil) ⇒ Enumerator

    Parameters:

  • #initialize(parent, first, direction, count_limit) ⇒ Enumerator

    Parameters:

    • parent (When::Coordinates::Residue)

      生成元の剰余類オブジェクト

    • first (When::TM::TemporalPosition)

      始点

    • direction (Symbol)

      :forward - 昇順, :reverse - 降順

    • count_limit (Integer)

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



632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
# File 'lib/when_exe/coordinates.rb', line 632

def initialize(*args)
  case args[1]
  when When::TimeValue
    first   = args[1] & args[0]
    first   = args[1] & (args[0] << 1) if args[2] == :reverse && first > args[1]
    args[1] = first
  when Range
    first   =  args[1].first & args[0]
    args[1] = (args[1].exclude_end?) ? (first...args[1].last) : (first..args[1].last)
  else
    raise TypeError, "Second Argument should be 'When::TM::(Temporal)Position'"
  end
  @period = When::TM::PeriodDuration.new(args[0].divisor,
                                         When::Coordinates::PRECISION[args[0].units] || When::DAY)
  super(*args)
end

Instance Method Details

#succWhen::TM::TemporalPosition

次の通日or通年を得る



610
611
612
613
614
615
616
617
# File 'lib/when_exe/coordinates.rb', line 610

def succ
  value = @current
  @current = (@count_limit.kind_of?(Numeric) && @count >= @count_limit) ? nil :
             (@current==:first) ? @first :
             (@direction==:forward) ? @first & @parent >> @count : @first &  @parent << @count
  @count  += 1
  return value
end