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.



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

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.



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

def by_part
  @by_part
end

#cashObject

Returns the value of attribute cash.



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

def cash
  @cash
end

#freq_indexObject

Returns the value of attribute freq_index.



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

def freq_index
  @freq_index
end

#listObject (readonly)

Returns the value of attribute list.



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

def list
  @list
end

Instance Method Details

#_bound(seed, week_start) ⇒ Object



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

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

候補日時の生成



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

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