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


1413
1414
1415
1416
1417
1418
1419
1420
1421
# File 'lib/when_exe/icalendar.rb', line 1413

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


1359
1360
1361
# File 'lib/when_exe/icalendar.rb', line 1359

def by_part
  @by_part
end

#cashObject

Returns the value of attribute cash


1361
1362
1363
# File 'lib/when_exe/icalendar.rb', line 1361

def cash
  @cash
end

#freq_indexObject

Returns the value of attribute freq_index


1358
1359
1360
# File 'lib/when_exe/icalendar.rb', line 1358

def freq_index
  @freq_index
end

#listObject (readonly)

Returns the value of attribute list


1360
1361
1362
# File 'lib/when_exe/icalendar.rb', line 1360

def list
  @list
end

Instance Method Details

#_bound(seed, week_start) ⇒ Object


1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
# File 'lib/when_exe/icalendar.rb', line 1365

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

候補日時の生成


1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
# File 'lib/when_exe/icalendar.rb', line 1386

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