Module: When
- Defined in:
- lib/when_exe.rb,
lib/when_exe/inspect.rb,
lib/when_exe/version.rb,
lib/when_exe/basictypes.rb,
lib/when_exe/linkeddata.rb,
lib/when_exe/locales/af.rb,
lib/when_exe/locales/ar.rb,
lib/when_exe/locales/az.rb,
lib/when_exe/locales/bg.rb,
lib/when_exe/locales/bn.rb,
lib/when_exe/locales/bs.rb,
lib/when_exe/locales/ca.rb,
lib/when_exe/locales/cs.rb,
lib/when_exe/locales/cy.rb,
lib/when_exe/locales/da.rb,
lib/when_exe/locales/de.rb,
lib/when_exe/locales/el.rb,
lib/when_exe/locales/en.rb,
lib/when_exe/locales/eo.rb,
lib/when_exe/locales/es.rb,
lib/when_exe/locales/et.rb,
lib/when_exe/locales/eu.rb,
lib/when_exe/locales/fa.rb,
lib/when_exe/locales/fi.rb,
lib/when_exe/locales/fr.rb,
lib/when_exe/locales/gl.rb,
lib/when_exe/locales/he.rb,
lib/when_exe/locales/hi.rb,
lib/when_exe/locales/hr.rb,
lib/when_exe/locales/hu.rb,
lib/when_exe/locales/id.rb,
lib/when_exe/locales/is.rb,
lib/when_exe/locales/it.rb,
lib/when_exe/locales/ja.rb,
lib/when_exe/locales/kn.rb,
lib/when_exe/locales/ko.rb,
lib/when_exe/locales/lo.rb,
lib/when_exe/locales/lt.rb,
lib/when_exe/locales/lv.rb,
lib/when_exe/locales/mk.rb,
lib/when_exe/locales/mn.rb,
lib/when_exe/locales/ms.rb,
lib/when_exe/locales/nb.rb,
lib/when_exe/locales/ne.rb,
lib/when_exe/locales/nl.rb,
lib/when_exe/locales/nn.rb,
lib/when_exe/locales/or.rb,
lib/when_exe/locales/pl.rb,
lib/when_exe/locales/pt.rb,
lib/when_exe/locales/rm.rb,
lib/when_exe/locales/ro.rb,
lib/when_exe/locales/ru.rb,
lib/when_exe/locales/sk.rb,
lib/when_exe/locales/sl.rb,
lib/when_exe/locales/sr.rb,
lib/when_exe/locales/sv.rb,
lib/when_exe/locales/sw.rb,
lib/when_exe/locales/ta.rb,
lib/when_exe/locales/th.rb,
lib/when_exe/locales/tl.rb,
lib/when_exe/locales/tr.rb,
lib/when_exe/locales/uk.rb,
lib/when_exe/locales/ur.rb,
lib/when_exe/locales/uz.rb,
lib/when_exe/locales/vi.rb,
lib/when_exe/locales/wo.rb,
lib/when_exe/locales/zh.rb,
lib/when_exe/region/dee.rb,
lib/when_exe/region/pax.rb,
lib/when_exe/tmduration.rb,
lib/when_exe/locales/akt.rb,
lib/when_exe/region/m17n.rb,
lib/when_exe/region/pope.rb,
lib/when_exe/region/thai.rb,
lib/when_exe/region/yerm.rb,
lib/when_exe/calendarnote.rb,
lib/when_exe/locales/iast.rb,
lib/when_exe/region/bahai.rb,
lib/when_exe/region/mayan.rb,
lib/when_exe/region/roman.rb,
lib/when_exe/region/shire.rb,
lib/when_exe/region/world.rb,
lib/when_exe/ephemeris/sun.rb,
lib/when_exe/locales/de_AT.rb,
lib/when_exe/locales/de_CH.rb,
lib/when_exe/locales/en_AU.rb,
lib/when_exe/locales/en_CA.rb,
lib/when_exe/locales/en_GB.rb,
lib/when_exe/locales/en_IE.rb,
lib/when_exe/locales/en_IN.rb,
lib/when_exe/locales/en_NZ.rb,
lib/when_exe/locales/en_US.rb,
lib/when_exe/locales/en_ZA.rb,
lib/when_exe/locales/es_AR.rb,
lib/when_exe/locales/es_CL.rb,
lib/when_exe/locales/es_CO.rb,
lib/when_exe/locales/es_CR.rb,
lib/when_exe/locales/es_EC.rb,
lib/when_exe/locales/es_MX.rb,
lib/when_exe/locales/es_PA.rb,
lib/when_exe/locales/es_PE.rb,
lib/when_exe/locales/es_US.rb,
lib/when_exe/locales/es_VE.rb,
lib/when_exe/locales/fr_CA.rb,
lib/when_exe/locales/fr_CH.rb,
lib/when_exe/locales/hi_IN.rb,
lib/when_exe/locales/it_CH.rb,
lib/when_exe/locales/links.rb,
lib/when_exe/locales/pt_BR.rb,
lib/when_exe/locales/zh_CN.rb,
lib/when_exe/locales/zh_HK.rb,
lib/when_exe/locales/zh_TW.rb,
lib/when_exe/region/coptic.rb,
lib/when_exe/region/french.rb,
lib/when_exe/region/indian.rb,
lib/when_exe/region/jewish.rb,
lib/when_exe/region/korean.rb,
lib/when_exe/region/ryukyu.rb,
lib/when_exe/ephemeris/moon.rb,
lib/when_exe/locales/es_419.rb,
lib/when_exe/locales/locale.rb,
lib/when_exe/locales/zh_YUE.rb,
lib/when_exe/region/chinese.rb,
lib/when_exe/region/goddess.rb,
lib/when_exe/region/iranian.rb,
lib/when_exe/region/islamic.rb,
lib/when_exe/region/martian.rb,
lib/when_exe/region/tibetan.rb,
lib/when_exe/region/armenian.rb,
lib/when_exe/region/balinese.rb,
lib/when_exe/region/japanese.rb,
lib/when_exe/region/javanese.rb,
lib/when_exe/region/symmetry.rb,
lib/when_exe/region/weekdate.rb,
lib/when_exe/locales/autoload.rb,
lib/when_exe/mini_application.rb,
lib/when_exe/region/christian.rb,
lib/when_exe/ephemeris/planets.rb,
lib/when_exe/parts/method_cash.rb,
lib/when_exe/region/babylonian.rb,
lib/when_exe/region/discordian.rb,
lib/when_exe/region/east_asian.rb,
lib/when_exe/region/positivist.rb,
lib/when_exe/region/vietnamese.rb,
lib/when_exe/region/hanke_henry.rb,
lib/when_exe/region/tranquility.rb,
lib/when_exe/region/zoroastrian.rb,
lib/when_exe/region/world_season.rb,
lib/when_exe/region/chinese/notes.rb,
lib/when_exe/region/chinese/twins.rb,
lib/when_exe/region/chinese/epochs.rb,
lib/when_exe/region/japanese/twins.rb,
lib/when_exe/region/japanese/epochs.rb,
lib/when_exe/region/chinese/calendars.rb,
lib/when_exe/region/japanese/calendars.rb,
lib/when_exe/region/international_fixed.rb,
lib/when_exe/locales/encoding_conversion.rb,
lib/when_exe/region/vanishing_leprechaun.rb,
lib/when_exe/locales/transliteration_table.rb
Overview
Copyright © 2014 Takashi SUGA
You may use and/or modify this file according to the license described in the LICENSE.txt file included in this archive.
Defined Under Namespace
Modules: BasicTypes, CalendarTypes, Coordinates, EX, EncodingConversion, Ephemeris, GoogleAPI, Locale, Parts, RS, TM, TimeStandard, V Classes: CalendarNote
Constant Summary collapse
- SourceURI =
when_exe 用 International Resource Identifier
ENV["WHEN_EXE_BASE_URI"] || "http://hosi.org/When/"
- RootDir =
ルートディレクトリ(デフォルトでは lib の親ディレクトリ
ENV["WHEN_EXE_ROOT_DIR"] || File.dirname(__FILE__).sub(/\/[^\/]*\z/,'')
- PT1S =
1 second period duration
TM::PeriodDuration.new(nil,[0,0,0,1])
- PT1M =
1 minute period duration
TM::PeriodDuration.new(nil,[0,0,1,0])
- PT1H =
1 hour period duration
TM::PeriodDuration.new(nil,[0,1,0,0])
- P1D =
1 day period duration
TM::PeriodDuration.new([0,0,1])
- P1W =
1 week period duration
TM::PeriodDuration.new([0,0,7])
- P1M =
1 month period duration
TM::PeriodDuration.new([0,1,0])
- P1Y =
1 year period duration
TM::PeriodDuration.new([1,0,0])
- TimeValue =
kind of When::TM::Position or When::TM::TemporalPosition
TM::IndeterminateValue
- Week =
7 days week residue
When::Parts::Resource._instance('_co:Common::Week')
- Month =
Gregorian months
When::Parts::Resource._instance('_m:Calendar::Month')
- PlusInfinity =
+ ∞
TM::TemporalPosition.new({:indeterminated_position=>TimeValue::Max})
- MinusInfinity =
-
∞
-
TM::TemporalPosition.new({:indeterminated_position=>TimeValue::Min})
- UTF8 =
UTF-8 encoding
'.UTF-8'
- W31J =
Windows-31J encoding
'.Windows-31J'
- EUCJP =
eucJP encoding
'.eucJP'
- VERSION =
"0.4.4"
- YEARS =
"(C) 2011-2015"
- AUTHOR =
"Takashi SUGA"
- COPYRIGHT =
"#{YEARS} #{AUTHOR}"
- CENTURY =
分解能定数
-4
- DECADE =
-3
- YEAR =
-2
- MONTH =
-1
- WEEK =
-0.5
- DAY =
0
- HOUR =
1
- MINUTE =
2
- SECOND =
3
- STRING =
5
- SYSTEM =
(Float::MANT_DIG*0.3).to_i
Class Attribute Summary collapse
-
.logger ⇒ Logger
Logger オブジェクト.
-
.multi_thread ⇒ Boolean
readonly
マルチスレッド対応の場合 true.
Class Method Summary collapse
- ._const_missing ⇒ Object
-
._define_common_calendar_types(list = %w(UTC Gregorian Julian Civil))) ⇒ Object
When 直下に定数として定義する時法・暦法(明示的的追加).
-
._setup_(options = {}) ⇒ void
Initializations.
-
._setup_info ⇒ Hash
設定情報を取得する.
-
.at(time, options = {}) ⇒ When::TM::DateAndTime
指定日時に対応する When::TM::TemporalPosition の生成 (When::TM::DateAndTime of specified Time).
-
.Border(border) ⇒ When::Coordinates::Border
When::Coordinates::Border の生成/参照.
-
.Calendar(calendar) ⇒ When::TM::Calendar
When::TM::Calendar の生成/参照.
-
.CalendarEra(era) ⇒ When::TM::CalendarEra
When::TM::CalendarEra の生成/参照.
-
.CalendarNote(note) ⇒ When::CalendarNote
When::CalendarNote の生成/参照.
-
.client(server, port, query) ⇒ JSON
マイクロ・クライアントを実行する.
-
.Clock(clock) ⇒ When::Parts::Timezone::Base
When::TM::Clock の生成/参照.
-
.column(date, type) ⇒ Object
七曜表の一日分.
-
.config(path = File.expand_path($0) + '.config') ⇒ Object
設定ファイルを読み込む.
-
.const_missing(constant) ⇒ Object
When 直下に定数として定義する時法・暦法など(暗黙的追加).
-
.Duration(period, options = {}) ⇒ When::TM::Duration or Array<them>
When::TM::Duration の生成.
-
.era(key, epoch = nil, reverse = nil, options = {}) ⇒ Array<When::TM::CalendarEra>
When::TM::CalendarEra の検索.
-
.free_conv(*args, &block) ⇒ Array<Hash>, Array<Array<Numeric>>
日付の自由変換.
-
.Index(terms = nil, name = 'Month', options) ⇒ When::Coordinates::Index
When::Coordinates::Index の生成.
-
.Location(*args) ⇒ When::Coordinates::Spatial
When::Coordinates::Spatial の生成/参照.
-
.m17n(source, namespace = nil, locale = nil, options = {}) ⇒ When::BasicTypes::M17n or Array<them>
When::BasicTypes::M17n の生成/参照.
-
.M17n(source) ⇒ When::BasicTypes::M17n
When::BasicTypes::M17n の生成/参照.
-
.MonthName(name) ⇒ When::BasicTypes::M17n
月名.
-
.now(options = {}) ⇒ When::TM::DateAndTime
現在日時に対応する When::TM::TemporalPosition の生成 (When::TM::DateAndTime of now).
-
.Pair(trunk, branch = nil) ⇒ When::Coordinates::Pair
When::Coordinates::Pair の生成.
-
.Residue(day) ⇒ When::Coordinates::Residue
(also: day_of_week)
曜日(剰余類).
-
.Resource(iri, namespace = nil) ⇒ When::Parts::Resourc
(also: IRI)
When::Parts::Resource の生成/参照.
-
.server(port) ⇒ void
マイクロ・サーバーを起動する.
-
.TemporalPosition(*args, options = {}) ⇒ When::TM::TemporalPosition
(also: tm_pos)
When::TM::TemporalPosition の生成.
-
.today(options = {}) ⇒ When::TM::CalDate
本日に対応する When::TM::CalDate の生成 (When::TM::CalDate of today).
-
.when?(specification, options = {}) ⇒ When::TM::TemporalPosition, ...
Generation of Temporal Objetct, duration or When::Parts::GeometricComplex.
-
.Wikipedia(title, options = {}) ⇒ When::BasicTypes::M17n
Wikipedia を参照して When::BasicTypes::M17n を生成する.
Class Attribute Details
.logger ⇒ Logger
Logger オブジェクト
48 49 50 |
# File 'lib/when_exe.rb', line 48 def logger @logger end |
.multi_thread ⇒ Boolean (readonly)
マルチスレッド対応の場合 true
41 42 43 |
# File 'lib/when_exe.rb', line 41 def multi_thread @multi_thread end |
Class Method Details
._const_missing ⇒ Object
129 |
# File 'lib/when_exe.rb', line 129 alias :_const_missing :const_missing |
._define_common_calendar_types(list = %w(UTC Gregorian Julian Civil))) ⇒ Object
When 直下に定数として定義する時法・暦法(明示的的追加)
119 120 121 122 123 124 125 126 127 |
# File 'lib/when_exe.rb', line 119 def _define_common_calendar_types(list=%w(UTC Gregorian Julian Civil)) list.each do |calendar| resource = Parts::Resource._instance(calendar, '_c:') Parts::Resource.synchronize do Parts::Resource::ConstList << calendar const_set(calendar, resource) end end end |
._setup_(options = {}) ⇒ void
本メソッドでマルチスレッド対応の管理変数の初期化を行っている。 このため、本メソッド自体および本メソッドから呼んでいる各クラスの setup メソッドはスレッドセーフでない。
This method returns an undefined value.
Initializations
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/when_exe.rb', line 81 def _setup_(={}) @multi_thread = [:multi_thread] @logger = [:logger] Parts::MethodCash._setup_() Parts::Resource._setup_() Locale._setup_() Coordinates::Spatial._setup_([:location]) TM::CalendarEra._setup_([:order]) TM::Calendar._setup_ TM::Clock._setup_([:local]) TM::TemporalPosition._setup_([:format]) V::Event._setup_([:until]) V::Timezone._setup_ Parts::Timezone._setup_ TimeStandard._setup_([:leap_seconds]) end |
._setup_info ⇒ Hash
設定情報を取得する
102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/when_exe.rb', line 102 def _setup_info {:multi_thread => @multi_thread}. update(Parts::MethodCash._setup_info). update(Parts::Resource._setup_info). update(Locale._setup_info). update(Coordinates::Spatial._setup_info). update(TM::CalendarEra._setup_info). update(TM::Clock._setup_info). update(TM::TemporalPosition._setup_info). update(V::Event._setup_info). update(TimeStandard._setup_info) end |
.at(time, options = {}) ⇒ When::TM::DateAndTime
指定日時に対応する When::TM::TemporalPosition の生成 (When::TM::DateAndTime of specified Time)
574 575 576 577 578 579 580 581 582 583 584 585 |
# File 'lib/when_exe.rb', line 574 def at(time, ={}) = ._attr if .kind_of?(TM::TemporalPosition) [:frame] ||= 'Gregorian' [:frame] = Resource([:frame], '_c:') if [:frame].kind_of?(String) [:clock] ||= Clock(time.utc_offset) if time.kind_of?(::Time) jdt = TM::JulianDate.universal_time(time.to_f * TM::IntervalLength::SECOND, {:frame=>TM::Clock.get_clock()}) [:clock] = jdt.frame date = [:frame].jul_trans(jdt, ) date = TM::CalDate.new(date.cal_date, ) if [:precision] && [:precision] <= DAY return date end |
.Border(border) ⇒ When::Coordinates::Border
When::Coordinates::Border の生成/参照
791 792 793 794 795 796 797 798 799 800 801 |
# File 'lib/when_exe.rb', line 791 def Border(border) case border when Coordinates::Border ; return border when /\([-\d]+?\)/ ; border = "_co:MultiBorder?borders=#{border}" when /\A[^A-Z_]/i ; border = "_co:Border?border=#{border}" end Parts::Resource._instance(border, '_co:') do |iri| Coordinates::CalendarBorder.send(:_behalf_of, iri) end end |
.Calendar(calendar) ⇒ When::TM::Calendar
When::TM::Calendar の生成/参照
666 667 668 |
# File 'lib/when_exe.rb', line 666 def Calendar(calendar) Parts::Resource._instance(calendar, '_c:') end |
.CalendarEra(era) ⇒ When::TM::CalendarEra
When::TM::CalendarEra の生成/参照
686 687 688 689 690 |
# File 'lib/when_exe.rb', line 686 def CalendarEra(era) Parts::Resource._instance(era, '_e:') do |iri| TM::CalendarEra.send(:_behalf_of, iri) end end |
.CalendarNote(note) ⇒ When::CalendarNote
When::CalendarNote の生成/参照
676 677 678 |
# File 'lib/when_exe.rb', line 676 def CalendarNote(note) Parts::Resource._instance(note, '_n:') end |
.client(server, port, query) ⇒ JSON
mini_application
マイクロ・クライアントを実行する
96 97 98 99 100 101 102 103 |
# File 'lib/when_exe/mini_application.rb', line 96 def client(server, port, query) TCPSocket.open(server, port.to_i) do |socket| socket.puts(query) results = JSON.parse(socket.gets.force_encoding("UTF-8")) results = Hash[*results.flatten(1)] if results[0].kind_of?(Array) _to_symbol(results) end end |
.Clock(clock) ⇒ When::Parts::Timezone::Base
When::TM::Clock の生成/参照
720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 |
# File 'lib/when_exe.rb', line 720 def Clock(clock) case clock when Parts::Timezone::Base ; return clock when 'Z', 0 ; return UTC when Numeric ; return Parts::Resource._instance("_tm:Clock?label=" + TM::Clock.to_hms(clock)) when /\A#{CalendarTypes::TimeSystems}/ ; return Parts::Resource._instance('_c:' + clock) when String ; else ; raise TypeError, "Invalid Type: #{clock.class}" end c = TM::Clock[clock] || V::Timezone[clock] return c if c clock, = clock.split('?') hms = TM::Clock.to_hms(clock) return Parts::Timezone[clock] unless hms iri = "_tm:Clock?label=" + hms iri += "&" + if Parts::Resource._instance(iri) end |
.column(date, type) ⇒ Object
七曜表の一日分
141 142 143 144 145 146 147 148 149 |
# File 'lib/when_exe/mini_application.rb', line 141 def column(date, type) case type when When::YEAR ; date.strftime("%Y") when When::MONTH ; date.strftime("%B %Y") when When::WEEK ; nil when When::DAY ; date[0] else ; '-' end end |
.config(path = File.expand_path($0) + '.config') ⇒ Object
設定ファイルを読み込む
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/when_exe/mini_application.rb', line 32 def config(path=File.($0) + '.config') config = {} open(path, 'r') do |file| while (line=file.gets) next if line =~ /\A\s*#/ key, *value = line.chomp.split(':') value = value[0] if value.size <= 1 config[key] = value end end config rescue {} end |
.const_missing(constant) ⇒ Object
When 直下に定数として定義する時法・暦法など(暗黙的追加)
134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/when_exe.rb', line 134 def const_missing(constant) sgn, *args = TM::PeriodDuration._to_array(constant.to_s) return const_set(constant, TM::PeriodDuration.new(*args)) if sgn iri = Parts::Resource._abbreviation_to_iri(constant) return _const_missing(constant) unless iri resource = Parts::Resource._instance(iri) return const_get(constant) if const_defined?(constant) Parts::Resource.synchronize do Parts::Resource::ConstList << constant const_set(constant, resource) end end |
.Duration(period, options = {}) ⇒ When::TM::Duration or Array<them>
When::TM::Duration の生成
624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 |
# File 'lib/when_exe.rb', line 624 def Duration(period, ={}) case period when Array period.map {|e| Duration(e, )} when TM::Duration period when 0 TM::IntervalLength.new(0, 'day') when Numeric [TM::Duration::YEAR, TM::Duration::MONTH, TM::Duration::WEEK, TM::Duration::DAY, TM::Duration::HOUR, TM::Duration::MINUTE, TM::Duration::SECOND].each do |unit| div, mod = period.divmod(unit) return TM::IntervalLength.new(div, TM::Duration::Unit.invert[unit]) if mod == 0 end TM::IntervalLength.new(period, 'system') when String # IntervalLength args = TM::IntervalLength._to_array(period) return TM::IntervalLength.new(*args) if args # PeriodDuration sign, *args = TM::PeriodDuration._to_array(period) raise TypeError, "Argument 'period' is not a Duration" unless (sign) args << duration = TM::PeriodDuration.new(*args) return (sign >= 0) ? duration : -duration else nil end end |
.era(key, epoch = nil, reverse = nil, options = {}) ⇒ Array<When::TM::CalendarEra>
ヒット数が不足している場合は、setup で指定した順序で When::TM::CalendarEra オブジェクトを生成しつつ読み込んで検索する。
When::TM::CalendarEra の検索
708 709 710 |
# File 'lib/when_exe.rb', line 708 def era(*args) TM::CalendarEra._instance(*args) end |
.free_conv(*args, &block) ⇒ Array<Hash>, Array<Array<Numeric>>
暦法のIRI, When.exe Standard Expression, 最良近似分数列の分母分子などを文字列で指定
mini_application
日付の自由変換
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/when_exe/mini_application.rb', line 116 def free_conv(*args, &block) calendars, dates, numbers, methods, output, = _parse_command(args) if numbers.size >= 2 && calendars.size == 0 result = [] When::Coordinates::Residue.new(numbers[0], numbers[1]).each { |v| result << v } return result end block ||= if methods.size == 0 lambda {|date| date.send(*output)} else lambda {|date, type| column(date, type)} end _free_conv(calendars, dates, methods, output, , &block) end |
.Index(terms = nil, name = 'Month', options) ⇒ When::Coordinates::Index
When::Coordinates::Index の生成
915 916 917 |
# File 'lib/when_exe.rb', line 915 def Index(*args) Coordinates::Index.new(*args) end |
.Location(location) ⇒ When::Coordinates::Spatial .Location(longitude, latitide, altitide = 0, datum = 'Earth') ⇒ When::Coordinates::Spatial
longitudeが経度を意味する文字列, latitude が緯度を意味する文字列の場合、 引数の順番によらず、それぞれ経度および緯度と解釈する
When::Coordinates::Spatial の生成/参照
758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 |
# File 'lib/when_exe.rb', line 758 def Location(*args) case args[0] when Coordinates::Spatial ; return args[0] when Parts::Timezone ; return args[0].location when String ; return Parts::Resource._instance(args[0], '_l:') if args.size == 1 when Numeric ; else ; raise TypeError, "Invalid Type: #{args[0].class}" end rest = [] longitude = latitude = nil args.each do |arg| case arg when /\A#{Coordinates::MATCH['EW']}\s*[.@\d]/, /[.@\d]\s*#{Coordinates::MATCH['EW']}\z/; longitude = arg when /\A#{Coordinates::MATCH['NS']}\s*[.@\d]/, /[.@\d]\s*#{Coordinates::MATCH['NS']}\z/; latitude = arg else ; rest << arg end end longitude ||= rest.shift latitude ||= rest.shift raise ArgumentError, "too few arguments" unless longitude && latitude altitude, datum = rest iri = "_l:long=#{longitude}&lat=#{latitude}" iri += "&alt=#{altitude}" if altitude iri += "&datum=#{datum}" if datum Parts::Resource._instance(iri) end |
.m17n(source, namespace = nil, locale = nil, options = {}) ⇒ When::BasicTypes::M17n or Array<them>
When::BasicTypes::M17n の生成/参照
852 853 854 855 856 857 858 859 860 861 862 863 |
# File 'lib/when_exe.rb', line 852 def m17n(source, namespace=nil, locale=nil, ={}) case source when Array ; BasicTypes::M17n.new(source, namespace, locale, ) when BasicTypes::M17n ; source when String source = EncodingConversion.to_internal_encoding(source) return self[$1] if source =~ /\A\s*\[((\.{1,2}|::)+[^\]]+)\]/ && self.kind_of?(When::Parts::Resource) return Parts::Resource[$1] if source =~ /\A\s*\[::([^\]]+)\]/ BasicTypes::M17n.new(source, namespace, locale, ) else ; raise TypeError, "Invalid Type: #{source.class}" end end |
.M17n(source) ⇒ When::BasicTypes::M17n
When::BasicTypes::M17n の生成/参照
837 838 839 |
# File 'lib/when_exe.rb', line 837 def M17n(source) Parts::Resource._instance(source, '_m:') end |
.MonthName(name) ⇒ When::BasicTypes::M17n
月名
827 828 829 |
# File 'lib/when_exe.rb', line 827 def MonthName(name) When::BasicTypes::M17n.month_name(name) end |
.now(options = {}) ⇒ When::TM::DateAndTime
メソッド実行時の「現在日時」である。@indeterminated_position は設定しないので自動的に日時が進むことはない
現在日時に対応する When::TM::TemporalPosition の生成 (When::TM::DateAndTime of now)
596 597 598 |
# File 'lib/when_exe.rb', line 596 def now(={}) When.at(Time.now, ) end |
.Pair(trunk, branch = nil) ⇒ When::Coordinates::Pair
When::Coordinates::Pair の生成
927 928 929 |
# File 'lib/when_exe.rb', line 927 def Pair(trunk, branch=nil) Coordinates::Pair._force_pair(trunk, branch) end |
.Residue(day) ⇒ When::Coordinates::Residue Also known as: day_of_week
曜日(剰余類)
812 813 814 |
# File 'lib/when_exe.rb', line 812 def Residue(day) When::Coordinates::Residue.to_residue(day) end |
.Resource(iri, namespace = nil) ⇒ When::Parts::Resourc Also known as: IRI
When::Parts::Resource の生成/参照
896 897 898 |
# File 'lib/when_exe.rb', line 896 def Resource(iri, namespace=nil) Parts::Resource._instance(iri, namespace) end |
.server(port) ⇒ void
mini_application
This method returns an undefined value.
マイクロ・サーバーを起動する
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/when_exe/mini_application.rb', line 56 def server(port) config = When.config TCPServer.open(port.to_i) do |socket| puts Time.now._log_('%FT%X.%L') + ': Start' loop do Thread.start(socket.accept) do |client| query = client.gets.chomp.force_encoding("UTF-8") start = Time.now puts start._log_('%FT%X.%L') + ': Query - ' + When::Locale.translate(query, config['!']) begin result = free_conv(*query.split(/\s+/)) result = When::Locale.translate(result, config['!']) client.puts JSON.generate(Array(_to_string(result))).to_s stop = Time.now puts stop._log_('%FT%X.%L') + ": Respond (%7.0f ms)" % (1000 * (stop.to_f - start.to_f)) rescue => err puts Time.now._log_('%FT%X.%L') + ': error - ' + err.to_s client.puts JSON.generate({:error=>query}).to_s end client.close end end end rescue Exception => e puts Time.now._log_('%FT%X.%L') + ': Exception - ' + e.to_s ensure puts Time.now._log_('%FT%X.%L') + ': Done.' end |
.TemporalPosition(*args, options = {}) ⇒ When::TM::TemporalPosition Also known as: tm_pos
When::TM::TemporalPosition の生成
557 558 559 |
# File 'lib/when_exe.rb', line 557 def TemporalPosition(*args) TM::TemporalPosition._temporal_position(*args) end |
.today(options = {}) ⇒ When::TM::CalDate
メソッド実行時の「本日」である。@indeterminated_position は設定しないので自動的に日時が進むことはない
options で時間帯を指定しても「本日」の決定に使用するのみで、戻り値には反映されない
本日に対応する When::TM::CalDate の生成 (When::TM::CalDate of today)
610 611 612 |
# File 'lib/when_exe.rb', line 610 def today(={}) now(.merge({:precision=>DAY})) end |
.when?(specification, options = {}) ⇒ When::TM::TemporalPosition, ...
Generation of Temporal Objetct, duration or When::Parts::GeometricComplex
522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 |
# File 'lib/when_exe.rb', line 522 def when?(specification, ={}) # フォーマットごとの処理 case specification when TM::TemporalPosition, Parts::GeometricComplex ; specification when TM::Position ; specification.any_other when Array ; begin = TM::TemporalPosition.() ; specification.map {|e| when?(e, )} end when /\Atoday((\^|%5E){1,2}(.+))?\z/i ; today($3 ? {:frame=>$3}.update() : ) when /\Anow((\^|%5E){1,2}(.+))?\z/i ; now( $3 ? {:frame=>$3}.update() : ) when /(JDN|MJD|SDN|CEP)(\z|\^|%5E)/i ; TM::JulianDate.parse(specification, ) when /[\n\r]+/ ; when?(specification.split(/[\n\r]+/), ) when String ; TM::TemporalPosition._instance(EncodingConversion.to_internal_encoding(specification), ) when Numeric ; TM::JulianDate.new(+specification, TM::TemporalPosition.()) else ; Calendar([:frame] || 'Gregorian').jul_trans(specification, ) end end |
.Wikipedia(title, options = {}) ⇒ When::BasicTypes::M17n
生成した多言語対応文字列の what が nil でない場合、 その項目の位置情報を表わす When::Coordinates::Spatial を指す
Wikipedia を参照して When::BasicTypes::M17n を生成する
878 879 880 881 882 883 884 885 886 887 |
# File 'lib/when_exe.rb', line 878 def Wikipedia(title, ={}) locale = .delete(:locale) || 'en' title = EncodingConversion.to_internal_encoding(title) entry, query = title.split('?', 2) url = "https://#{locale}.wikipedia.org/wiki/#{URI.encode(entry).gsub(' ', '_')}" Locale.send(:wikipedia_object, url, ) unless .empty? url += '?' + query if query object = Parts::Resource._instance(url) object.to_m17n end |