Class: When::V::Event::Enumerator::Logic

Inherits:
Object
  • Object
show all
Defined in:
lib/when_exe/icalendar.rb

Overview

多重繰り返しロジック

Direct Known Subclasses

Enumerator, Hour, Month, Monthday, Residue, Second, Weekno, Yearday

Defined Under Namespace

Classes: Enumerator, Hour, Minute, Month, Monthday, Residue, Second, Weekday, Weekno, Yearday

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(by_part, list) ⇒ Logic

Returns a new instance of Logic.



1421
1422
1423
1424
1425
1426
1427
1428
1429
# File 'lib/when_exe/icalendar.rb', line 1421

def initialize(by_part, list)
  @by_part = by_part
  @list =
    case list
    when String ; When::Coordinates::Pair::_en_pair_array(list)
    when Array  ;
    else        ; [list]
    end
end

Instance Attribute Details

#by_partObject (readonly)

Returns the value of attribute by_part.



1367
1368
1369
# File 'lib/when_exe/icalendar.rb', line 1367

def by_part
  @by_part
end

#cashObject

Returns the value of attribute cash.



1369
1370
1371
# File 'lib/when_exe/icalendar.rb', line 1369

def cash
  @cash
end

#freq_indexObject

Returns the value of attribute freq_index.



1366
1367
1368
# File 'lib/when_exe/icalendar.rb', line 1366

def freq_index
  @freq_index
end

#listObject (readonly)

Returns the value of attribute list.



1368
1369
1370
# File 'lib/when_exe/icalendar.rb', line 1368

def list
  @list
end

Instance Method Details

#_bound(seed, week_start) ⇒ Object



1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
# File 'lib/when_exe/icalendar.rb', line 1373

def _bound(seed, week_start)
  if (@freq_index == When::WEEK)
    # 週の初め
    bound = seed & week_start
    if (bound == seed)
      lower_bound  = bound.floor(When::DAY, nil)
      higher_bound = lower_bound  + week_start.duration
    else
      higher_bound = bound.floor(When::DAY, nil)
      lower_bound  = higher_bound - week_start.duration
    end
  else
    # 指定桁で切り捨て/切り上げ
    lower_bound  = seed.floor(@freq_index, nil)
    higher_bound = seed.ceil(@freq_index, nil)
  end
  return [lower_bound, higher_bound]
end

#_candidates(lower_bound, higher_bound) ⇒ Object

候補日時の生成



1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
# File 'lib/when_exe/icalendar.rb', line 1394

def _candidates(lower_bound, higher_bound)
  # TODO unitBaseの扱い
  return @list.map { |ord|
    if (ord >= 0)
      period = ord - 1
      bound  = lower_bound
    else
      period = ord
      bound  = higher_bound
    end
    index  = PostFreqIndex[@by_part]
    period = ord-bound[index] if (index>0)
    result = bound + When::TM::PeriodDuration.new(period, index)
    if period > 0 && result.universal_time < lower_bound.universal_time
      clock  = result.clock
      case clock.tz_prop
      when When::V::TimezoneProperty ; clock = clock.tz_prop.tzoffsetto
      when When::Parts::Timezone     ; clock = clock.tz_prop.standard
      end
      result = result._copy({:date=>result.cal_date, :validate=>:done, :events=>nil,
                             :time=>result.clk_time._copy({:clock=>clock})})
    end
    result
  }
end