剰余類
曜日の番号
day : Numeric or String
Numeric - day をそのまま返します
String - 最初の2文字から決定した曜日の番号を返します
returns : Integer
月曜を 0 とする曜日番号
# File when/coordinates.rb, line 62
62: def day_of_week(day)
63: case day
64: when Numeric ; return day
65: when nil ; return 0
66: end
67:
68: week = When.IRI('_co:CommonResidue::Week').child
69: 7.times do |i|
70: return i if week[i].label =~ /#{day[/^../]}/
71: end
72: return nil
73: end
汎用の mod
nn を dd で「割った」商(quot), 余り(rem)および除数(div)を返します。
nn : Numeric
被除数
dd : Block
nn = rem + dd(quot)
div = dd(quot+1)-dd(quot)
となるように rem, div, quot を決めたい手続き
returns : quot, rem, div
remは非負、quotは Integer
# File when/coordinates.rb, line 88
88: def mod(nn, &dd)
89: u = dd.call(0)
90: y = ((nn-u)*256).divmod(dd.call(256)-u)[0] - 1
91: w1, w2 = dd.call(y), dd.call(y+1)
92: until w1 <= nn && nn < w2
93: if w2 <= nn then y, w1, w2 = y+1, w2, dd.call(y+2)
94: else y, w1, w2 = y-1, dd.call(y-1), w1
95: end
96: end
97: return y, nn-w1, w2-w1
98: end
オブジェクトの生成
remainder : Numeric
剰余
divisor : Integer
法(>0)
carry : Integer
繰り上がり(デフォルト : 0)
label : String (include When::BasicTypes::M17n)
名前(デフォルト : nil)
units : Hash
単位(デフォルト : {})
'DAY' => Numeric - 通日に対して使用する場合のオフセット
'YEAR' => Numeric - 通年に対して使用する場合のオフセット
# File when/coordinates.rb, line 323
323: def initialize(*args)
324: # units の取得
325: options =_get_options(args).dup
326: units = {}
327: list = []
328: options.each_pair do |key, value|
329: if (PRECISION[key.upcase])
330: list << key
331: units[key.upcase] = self.class._to_num(value)
332: end
333: end
334: list.each do |key|
335: options.delete(key)
336: end
337: options['units'] ||= {}
338: options['units'].update(units)
339: _set_variables(options)
340: @units ||= {}
341:
342: # その他の変数
343: remainder, divisor, carry, label = args
344: @label = label || @label
345: @label = m17n(@label, options) if (@label)
346: _sequence
347: @remainder = self.class._to_num(remainder || @remainder)
348: @divisor = self.class._to_num(divisor || @divisor )
349: @carry = self.class._to_num(carry || @carry )
350: raise RangeError, "Divisor shoud be Positive Numeric" if (@divisor <= 0)
351: carry, @remainder = @remainder.divmod(@divisor)
352: @carry += carry
353: end
剰余
other : When::TM::(Temporal)Position or Numeric(include When::Coordinates::Pair) returns : the class same as the 'other'
# File when/coordinates.rb, line 280
280: def %(other)
281: case other
282: when When::TM::TemporalPosition, When::TM::Position
283: return self[other % self]
284: when Pair
285: return Pair.new(self % other.trunk, other.branch)
286: when Numeric
287: keys = @units.keys
288: d = (keys.size == 1) ? @units[keys[0]] : (@units['DAY']||0)
289: return (other-d) % @divisor
290: else
291: raise TypeError, "The right operand shoud be Numeric or When::TM::(Temporal)Position"
292: end
293: end
剰余類の共通集合
other : When::Coordinates::Residue returns : When::Coordinates::Residue
# File when/coordinates.rb, line 255
255: def &(other)
256: case other
257: when Residue
258: m = self.class._china([@remainder, @divisor], [other.remainder, other.divisor])
259: return nil unless (m)
260: return self.class.new(*(m << @carry << @units))
261: when Pair
262: return Pair.new(self & other.trunk, other.branch)
263: when Numeric
264: keys = @units.keys
265: d = (keys.size == 1) ? @units[keys[0]] : (@units['DAY']||0)
266: c, m = (other-d).divmod(@divisor)
267: c += 1 if (m > @remainder)
268: return (c + @carry) * @divisor + @remainder + d
269: else
270: return other & self
271: end
272: end
remainderの加算
other : Numeric returns : When::Coordinates::Residue
# File when/coordinates.rb, line 213
213: def +(other)
214: carry, remainder = (@remainder + other).divmod(@divisor)
215: return self.class.new(remainder, @divisor, @carry+carry, @units)
216: end
remainderの減算
other : Numeric returns : When::Coordinates::Residue
# File when/coordinates.rb, line 224
224: def -(other)
225: carry, remainder = (@remainder - other).divmod(@divisor)
226: return self.class.new(remainder, @divisor, @carry+carry, @units)
227: end
carryの加算
other : Numeric returns : When::Coordinates::Residue
# File when/coordinates.rb, line 235
235: def <<(other)
236: return self.class.new(@remainder, @divisor, @carry+other, @units)
237: end
carryの減算
other : Numeric returns : When::Coordinates::Residue
# File when/coordinates.rb, line 245
245: def >>(other)
246: return self.class.new(@remainder, @divisor, @carry-other, @units)
247: end
remainder の指定
remainder : Numeric
指定値を@remainderとする
returns : When::Coordinates::Residue
# File when/coordinates.rb, line 202
202: def [](remainder)
203: return super if !remainder.kind_of?(Numeric) || (child && child.length == @divisor)
204: self.class.new(@remainder+remainder, @divisor, @carry, @units)
205: end
units の指定
arg : String
あらかじめ units に指定した単位を用いる
returns : When::Coordinates::Residue
# File when/coordinates.rb, line 179
179: def to(arg)
180: return nil unless @units[arg]
181: self.class.new(@remainder, @divisor, @carry, {arg=>@units[arg]})
182: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.