Class: When::TM::IntervalLength
- Defined in:
- lib/when_exe/tmobjects.rb
Overview
ISO 11404 の時間間隔に基づいて定義された When::TM::Duration の subclass
see gml schema
Constant Summary collapse
- Alias =
{'Y'=>'year', 'M'=>'month' , 'D'=>'day', 'W'=>'week', 'S'=>'system', 'h'=>'hour', 'm'=>'minute', 's'=>'second'}
Constants inherited from Duration
Duration::DAY, Duration::DurationUnits, Duration::HOUR, Duration::MINUTE, Duration::MONTH, Duration::SECOND, Duration::SYSTEM, Duration::Unit, Duration::UnitName, Duration::WEEK, Duration::YEAR
Instance Attribute Summary collapse
-
#factor ⇒ Integer
readonly
基底のべき乗を行う指数.
-
#radix ⇒ Integer
readonly
時間単位となる乗数の基底となる正の整数.
-
#unit ⇒ String
readonly
時間間隔を表現するために使用した測定単位の名称.
-
#unit_quantity ⇒ Numeric
readonly
測定単位の大きさ.
-
#value ⇒ Numeric
readonly
時間間隔の長さ / 測定単位.
Attributes inherited from Duration
Class Method Summary collapse
-
._to_array(interval) ⇒ Array<Numeric, String>
Interval Length 形式の表現を分解して配列化する.
-
.difference(ended, begun) ⇒ When::TM::IntervalLength
オブジェクトの生成(終点と始点を指定).
Instance Method Summary collapse
-
#*(times) ⇒ When::TM::IntervalLength
乗算.
-
#+(other) ⇒ When::TM::IntervalLength, other と同じクラス
加算.
-
#-(other) ⇒ When::TM::IntervalLength
減算.
-
#-@ ⇒ When::TM::IntervalLength
符号反転.
-
#/(other) ⇒ When::TM::IntervalLength, Numeric
除算.
-
#date ⇒ nil
日付配列.
-
#initialize(value, unit = 'system', factor = 0, radix = 10) ⇒ IntervalLength
constructor
オブジェクトの生成.
-
#time ⇒ Numeric
時刻配列.
-
#to_interval_length ⇒ When::TM::IntervalLength
When::TM::IntervalLength への変換.
-
#to_s ⇒ String
文字列化.
-
#weeks ⇒ nil
暦週配列.
Methods inherited from Duration
#<=>, #==, #[], #_enumerator, #abs, #after, #before, #coerce, dhms, #sign, #to_as_duration, #to_dhms, #to_duration, #to_f, #to_i, #to_period_duration, unit
Constructor Details
#initialize(value, unit = 'system', factor = 0, radix = 10) ⇒ IntervalLength
オブジェクトの生成
793 794 795 796 797 798 799 800 801 |
# File 'lib/when_exe/tmobjects.rb', line 793 def initialize(value, unit='system', factor=0, radix=10) @value, @factor, @radix = value, factor, radix @unit_quantity = Unit[unit.downcase] || Unit[Alias[unit[0..0]]] if unit.kind_of?(String) @unit_quantity ||= unit.to_f raise TypeError, "Wrong Unit Type: #{unit}" unless @unit_quantity.kind_of?(Numeric) @unit = UnitName[@unit_quantity] || When::Coordinates::Pair._en_number(@unit_quantity).to_s @duration = @value * @radix ** (-@factor) * @unit_quantity end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object (private)
When::TM::IntervalLength で定義されていないメソッドは処理を @duration (type:Numeric) に委譲する
その他のメソッド
826 827 828 |
# File 'lib/when_exe/tmobjects.rb', line 826 def method_missing(name, *args, &block) @duration.send(name.to_sym, *args, &block) end |
Instance Attribute Details
#factor ⇒ Integer (readonly)
基底のべき乗を行う指数
633 634 635 |
# File 'lib/when_exe/tmobjects.rb', line 633 def factor @factor end |
#radix ⇒ Integer (readonly)
時間単位となる乗数の基底となる正の整数
627 628 629 |
# File 'lib/when_exe/tmobjects.rb', line 627 def radix @radix end |
#unit ⇒ String (readonly)
時間間隔を表現するために使用した測定単位の名称
621 622 623 |
# File 'lib/when_exe/tmobjects.rb', line 621 def unit @unit end |
#unit_quantity ⇒ Numeric (readonly)
測定単位の大きさ
647 648 649 |
# File 'lib/when_exe/tmobjects.rb', line 647 def unit_quantity @unit_quantity end |
#value ⇒ Numeric
時間間隔の長さ / 測定単位
639 640 641 |
# File 'lib/when_exe/tmobjects.rb', line 639 def value @value end |
Class Method Details
._to_array(interval) ⇒ Array<Numeric, String>
Interval Length 形式の表現を分解して配列化する
595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 |
# File 'lib/when_exe/tmobjects.rb', line 595 def self._to_array(interval) return nil unless interval =~ /^([-+]?[\d.]+)(?:(E|X|\((\d+)\))([-+]?\d+))?([A-Za-z]+|\*([\d.]+)S)$/ value, radix, radix_quantity, factor, unit, unit_quantity = $~[1..6] value = When::Coordinates::Pair._en_number(value) radix = case radix when 'E', nil ; 10 when 'X' ; 60 else ; radix_quantity.to_i end factor = factor ? -factor.to_i : 0 return [value, unit_quantity, factor, radix] if unit_quantity unit_quantity = Unit[unit.downcase] || Unit[Alias[unit[0..0]]] return [value, UnitName[unit_quantity], factor, radix] if unit_quantity return nil end |
.difference(ended, begun) ⇒ When::TM::IntervalLength
オブジェクトの生成(終点と始点を指定)
812 813 814 815 816 |
# File 'lib/when_exe/tmobjects.rb', line 812 def self.difference(ended, begun) precision = [ended.precision, begun.precision].min return new(ended-begun) if precision > When::DAY return new(ended.to_i - begun.to_i, unit='day') end |
Instance Method Details
#*(times) ⇒ When::TM::IntervalLength
乗算
736 737 738 739 740 741 |
# File 'lib/when_exe/tmobjects.rb', line 736 def *(times) interval = self.dup interval.value = times * @value interval.duration = times * @duration return interval end |
#+(other) ⇒ When::TM::IntervalLength, other と同じクラス
加算
703 704 705 706 707 708 709 710 711 712 713 |
# File 'lib/when_exe/tmobjects.rb', line 703 def +(other) case other when Duration ; diff = other.duration when Numeric ; diff = other * SECOND else ; return other + self end interval = self.dup interval.duration = @duration + diff internal.value = interval.duration / (@radix ** (-@factor) * @unit_quantity) return interval end |
#-(other) ⇒ When::TM::IntervalLength
減算
723 724 725 726 727 728 |
# File 'lib/when_exe/tmobjects.rb', line 723 def -(other) interval = self.dup interval.duration = @duration - (other.kind_of?(Duration) ? other.duration : other * SECOND) internal.value = interval.duration / (@radix ** (-@factor) * @unit_quantity) return interval end |
#-@ ⇒ When::TM::IntervalLength
符号反転
686 687 688 689 690 691 |
# File 'lib/when_exe/tmobjects.rb', line 686 def -@ interval = self.dup interval.value = -@value interval.duration = -@duration return interval end |
#/(other) ⇒ When::TM::IntervalLength, Numeric
除算
752 753 754 |
# File 'lib/when_exe/tmobjects.rb', line 752 def /(other) other.kind_of?(Duration) ? @duration / other.duration : self * (1.0 / other) end |
#date ⇒ nil
日付配列
667 668 669 |
# File 'lib/when_exe/tmobjects.rb', line 667 def date nil end |
#time ⇒ Numeric
時刻配列
656 657 658 |
# File 'lib/when_exe/tmobjects.rb', line 656 def time [0, 0, @duration / SECOND] end |
#to_interval_length ⇒ When::TM::IntervalLength
When::TM::IntervalLength への変換
781 782 783 |
# File 'lib/when_exe/tmobjects.rb', line 781 def to_interval_length self.dup end |
#to_s ⇒ String
文字列化
760 761 762 763 764 765 766 767 768 769 770 771 772 |
# File 'lib/when_exe/tmobjects.rb', line 760 def to_s expression = @value.to_s unless @factor == 0 case @radix when 10 ; expression += 'E' when 60 ; expression += 'X' else ; expression += '(%d)' % @radix end expression += '%+d' % (-@factor) end expression += Alias.invert[@unit] || "*#{When::Coordinates::Pair._en_number(@unit)}S" return expression end |
#weeks ⇒ nil
暦週配列
678 679 680 |
# File 'lib/when_exe/tmobjects.rb', line 678 def weeks nil end |