Class: When::Coordinates::LeapSeconds

Inherits:
Pair show all
Defined in:
lib/when_exe/coordinates.rb

Overview

暦座標値

閏秒のある暦座標の値を表現する

Constant Summary

Constants inherited from Pair

Pair::DL0, Pair::DL1, Pair::DL2

Instance Attribute Summary collapse

Attributes inherited from Pair

#branch, #sum, #trunk

Instance Method Summary collapse

Methods inherited from Pair

#%, #*, #+@, #-@, _de_pair, _en_number, _en_pair, _en_pair_array, _en_pair_date_time, _force_pair, _format, #_to_hash_value

Methods inherited from Numeric

#to_day_of_week, #to_month_name, #to_pair, #unit_duration, #unit_interval_length, #unit_period_duration

Methods included from TM::TemporalPosition::Conversion

#julian_date, #tm_position

Constructor Details

#initialize(trunk, branch, second) ⇒ LeapSeconds

オブジェクトの生成

Parameters:



1196
1197
1198
1199
1200
# File 'lib/when_exe/coordinates.rb', line 1196

def initialize(trunk, branch, second)
  @second     = second
  @int, @frac = trunk.divmod(second)
  super(trunk, branch)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class When::Coordinates::Pair

Instance Attribute Details

#fracFloat (readonly)

trunk の小数部

Returns:

  • (Float)


1123
1124
1125
# File 'lib/when_exe/coordinates.rb', line 1123

def frac
  @frac
end

#intInteger (readonly)

trunk の整数部

Returns:

  • (Integer)


1116
1117
1118
# File 'lib/when_exe/coordinates.rb', line 1116

def int
  @int
end

#secondNumeric (readonly)

閏秒の単位 / When::TM::Duration::SYSTEM

Returns:



1109
1110
1111
# File 'lib/when_exe/coordinates.rb', line 1109

def second
  @second
end

Instance Method Details

#+(other) ⇒ When::Coordinates::LeapSeconds

加算

Parameters:

Returns:



1132
1133
1134
1135
# File 'lib/when_exe/coordinates.rb', line 1132

def +(other)
  return self.class.new(@trunk + +other, @branch, @second) unless other.kind_of?(self.class)
  return self.class.new(@trunk + other.trunk, @branch + other.branch, @second)
end

#-(other) ⇒ When::Coordinates::LeapSeconds

減算

Parameters:

Returns:



1144
1145
1146
1147
# File 'lib/when_exe/coordinates.rb', line 1144

def -(other)
  return self.class.new(@trunk - +other, @branch, @second) unless other.kind_of?(self.class)
  return self.class.new(@trunk - other.trunk, @branch - other.branch, @second)
end

#<=>(other) ⇒ Integer

比較

Parameters:

Returns:

  • (Integer)

    (負,0,正) trunk の整数部, branch, trunk の小数部の順に比較する

Raises:

  • (ArgumentError)


1168
1169
1170
1171
1172
# File 'lib/when_exe/coordinates.rb', line 1168

def <=>(other)
  other = self.class.new(+other, 0, @second) unless other.kind_of?(self.class)
  raise ArgumentError, "length of unit 'second' mismatch" unless @second == other.second
  (@int <=> other.int).nonzero? || (@branch <=> other.branch).nonzero? || (@frac <=> other.frac)
end

#coerce(other) ⇒ Object

強制型変換



1186
1187
1188
# File 'lib/when_exe/coordinates.rb', line 1186

def coerce(other)
  [self.class.new(other, 0, @second), self]
end

#divmod(other) ⇒ When::Coordinates::LeapSeconds

商と剰余

Parameters:

Returns:



1156
1157
1158
1159
# File 'lib/when_exe/coordinates.rb', line 1156

def divmod(other)
  div, mod = @trunk.divmod(other)
  return div, self.class.new(mod, @branch, @second)
end

#to_s(zero = '') ⇒ String

文字列化

Parameters:

  • zero (String) (defaults to: '')

    @branch==0 を表現する文字列

Returns:



1180
1181
1182
# File 'lib/when_exe/coordinates.rb', line 1180

def to_s(zero='')
  return @trunk.to_s + (@branch==0 ? zero : DL2[(@branch/@second).floor])
end