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.



1376
1377
1378
1379
1380
1381
1382
1383
1384
# File 'lib/when_exe/icalendar.rb', line 1376

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.



1327
1328
1329
# File 'lib/when_exe/icalendar.rb', line 1327

def by_part
  @by_part
end

#cashObject

Returns the value of attribute cash.



1329
1330
1331
# File 'lib/when_exe/icalendar.rb', line 1329

def cash
  @cash
end

#freq_indexObject

Returns the value of attribute freq_index.



1326
1327
1328
# File 'lib/when_exe/icalendar.rb', line 1326

def freq_index
  @freq_index
end

#listObject (readonly)

Returns the value of attribute list.



1328
1329
1330
# File 'lib/when_exe/icalendar.rb', line 1328

def list
  @list
end

Instance Method Details

#_bound(seed, week_start) ⇒ Object



1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
# File 'lib/when_exe/icalendar.rb', line 1333

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

候補日時の生成



1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
# File 'lib/when_exe/icalendar.rb', line 1354

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
      result = result._copy({:date=>result.cal_date, :validate=>:done, :events=>nil,
                             :time=>result.clk_time._copy({:clock=>result.clock.tz_prop.tzoffsetto})})
    end
    result
  }
end