Module: When::Parts::Resource
- Extended by:
- Pool
- Includes:
- Synchronize
- Included in:
- BasicTypes::M17n, BasicTypes::Object, TM::Position, TM::TemporalPosition
- Defined in:
- lib/when_exe/parts/resource.rb
Overview
Resource which has ‘International Resource Identifier’
Defined Under Namespace
Modules: Pool, Synchronize Classes: Element, Enumerator
Constant Summary collapse
- LabelProperty =
nil
Class Attribute Summary collapse
- ._prefix ⇒ Object readonly
- ._prefix_index ⇒ Object readonly
- ._prefix_values ⇒ Object readonly
-
.base_uri ⇒ String
readonly
Base URI for When_exe Resources.
Instance Attribute Summary collapse
- #_pool ⇒ Object readonly
-
#child ⇒ Array<When::Parts::Resource>
readonly
self が has-a 関係で包含するオブジェクト.
-
#keys ⇒ Array<String>
readonly
strftime で有効な locale.
-
#locale ⇒ Array<String>
readonly
Resource包含階層で使用する locale.
-
#namespace ⇒ Hash
readonly
Resource包含階層で使用する namespace.
Class Method Summary collapse
- ._extract_prefix(path, capitalize = false) ⇒ Object
-
._instance(iri, namespace = nil) ⇒ When::Parts::Resource
オブジェクト生成&参照.
- ._parse(line, type = nil) ⇒ Object
- ._path_with_prefix(obj, simple = true) ⇒ Object
-
._setup_(base_uri = When::SourceURI) ⇒ void
初期化.
Instance Method Summary collapse
-
#[](iri) ⇒ When::parts::Resource
IRI または child の番号によるオブジェクト参照.
-
#^(other) ⇒ Enumerator
Enumerator 生成のダミー.
-
#each(*args, &block) ⇒ Enumerator
順次実行.
-
#enum_for(direction = :forward) ⇒ Object
(also: #to_enum)
オブジェクトを順に取り出す enumerator.
-
#hierarchy(klass = self.class) ⇒ When::Parts::Resource
self を包含するオブジェクト階層.
-
#include?(other) ⇒ Boolean
self が other を包含するか.
-
#included?(other) ⇒ Boolean
other が self を包含するか.
-
#iri ⇒ Object
オブジェクトの IRI.
-
#leaf? ⇒ Boolean
オブジェクト包含階層の末端か?.
-
#m17n(source, namespace = nil, locale = nil, options = {}) ⇒ When::BasicTypes::M17n or Array<them>
When::BasicTypes::M17n の生成/参照.
-
#map(&block) ⇒ Array
(also: #collect)
map, collect の再定義.
-
#next ⇒ When::Parts::Resource
(also: #succ)
次のオブジェクト.
-
#parent ⇒ When::Parts::Resource
self を直接に包含するオブジェクト.
-
#prev ⇒ When::Parts::Resource
前のオブジェクト.
-
#registered? ⇒ Boolean
IRIが付与されているか?.
Methods included from Pool
Methods included from Synchronize
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object (private)
その他のメソッド
When::Parts::GeometricComplex で定義されていないメソッドは
処理を @child (type: Array) に委譲する
807 808 809 |
# File 'lib/when_exe/parts/resource.rb', line 807 def method_missing(name, *args, &block) @child.send(name.to_sym, *args, &block) end |
Class Attribute Details
._prefix ⇒ Object (readonly)
137 138 139 |
# File 'lib/when_exe/parts/resource.rb', line 137 def _prefix @_prefix end |
._prefix_index ⇒ Object (readonly)
137 138 139 |
# File 'lib/when_exe/parts/resource.rb', line 137 def _prefix_index @_prefix_index end |
._prefix_values ⇒ Object (readonly)
137 138 139 |
# File 'lib/when_exe/parts/resource.rb', line 137 def _prefix_values @_prefix_values end |
.base_uri ⇒ String (readonly)
Base URI for When_exe Resources
134 135 136 |
# File 'lib/when_exe/parts/resource.rb', line 134 def base_uri @base_uri end |
Instance Attribute Details
#_pool ⇒ Object (readonly)
421 422 423 |
# File 'lib/when_exe/parts/resource.rb', line 421 def _pool @_pool end |
#child ⇒ Array<When::Parts::Resource> (readonly)
self が has-a 関係で包含するオブジェクト
427 428 429 |
# File 'lib/when_exe/parts/resource.rb', line 427 def child @child end |
#keys ⇒ Array<String> (readonly)
strftime で有効な locale
454 455 456 |
# File 'lib/when_exe/parts/resource.rb', line 454 def keys @keys end |
#locale ⇒ Array<String> (readonly)
Resource包含階層で使用する locale
When::BasicTypes::M17n の生成に使用する locale を定義する。
RFC 5545 に対する拡張である。
448 449 450 |
# File 'lib/when_exe/parts/resource.rb', line 448 def locale @locale end |
#namespace ⇒ Hash (readonly)
Resource包含階層で使用する namespace
When::BasicTypes::M17n の生成に使用する namespace を定義する。
RFC 5545 に対する拡張である。
xml で記述する場合には、本ライブラリ以外でも namespace を定義している。
438 439 440 |
# File 'lib/when_exe/parts/resource.rb', line 438 def namespace @namespace end |
Class Method Details
._extract_prefix(path, capitalize = false) ⇒ Object
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
# File 'lib/when_exe/parts/resource.rb', line 257 def _extract_prefix(path, capitalize=false) if (path =~ /^(.+?):+(.+)$/) prefix, klass = $~[1..2] if capitalize prefix = '_' + prefix.downcase klass = klass.capitalize if klass == klass.upcase end path = _prefix[prefix] + klass if (_prefix[prefix]) elsif capitalize && path =~ /^(v[^\/]+|daylight$|standard$)/i klass = path.sub(/^v/i, '').capitalize path = _prefix['_v'] + klass if When::V.const_defined?(klass) && When::V.const_get(klass).kind_of?(Class) end return path end |
._instance(iri, namespace = nil) ⇒ When::Parts::Resource
オブジェクト生成&参照
指定した iri の When::Parts::Resource オブジェクトを取得する。 当該オブジェクトが未登録であれば生成する。
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/when_exe/parts/resource.rb', line 185 def _instance(iri, namespace=nil) _setup_ unless @_pool # 配列は個別に処理 return iri.map {|e| _instance(e, namespace)} if iri.kind_of?(Array) # 文字列以外はそのまま返す return iri unless iri.instance_of?(String) # 階層がある場合は、階層をたどる iri = namespace + iri if namespace && iri !~ /^[_a-z\d]+:[^:]/i root, *leaves= iri.split(/::/) return leaves.inject(_instance(root)) {|obj,leaf| obj[leaf]} unless leaves==[] || iri =~ /\?/ # 登録ずみなら、参照 path, query = _extract_prefix(iri).split(/\?/, 2) iri = query ? (path + '?' + query) : path if When.multi_thread my_mutex = nil @_lock_.synchronize do @_pool ||= {} unless @_pool[iri] my_mutex = Mutex.new @_pool[iri] = my_mutex end end case @_pool[iri] when my_mutex; my_mutex.synchronize {_create_object(iri, path, query) } when Mutex ; @_pool[iri].synchronize { @_pool[iri] } else ; @_pool[iri] end else @_pool ||= {} @_pool[iri] ? @_pool[iri] : _create_object(iri, path, query) end end |
._parse(line, type = nil) ⇒ Object
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'lib/when_exe/parts/resource.rb', line 236 def _parse(line, type=nil) return line unless line.kind_of?(String) line.sub!(/\s#.*$/, '') return Locale._split($1) if type && line =~ /^#{type}:(.+)$/i return Locale._split(line) unless line =~ /^(\*)?([A-Z][-A-Z_]{0,255})(?:;(.*?))?:(.*)$/i marked, key, property, value = $~[1..4] element = Element.new(key, value, marked) if (property) element.attribute['.'] = property+':'+value property.split(/;/) do |pr| prop = Element.new(*pr.split(/=/, 2)) element.attribute[prop.predicate] = prop end else element.attribute['.'] = value end return element end |
._path_with_prefix(obj, simple = true) ⇒ Object
223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/when_exe/parts/resource.rb', line 223 def _path_with_prefix(obj, simple=true) _setup_ unless @_pool path = obj.kind_of?(Class) ? obj.to_s.sub(/^When::/, base_uri).gsub(/::/, '/') : obj.iri return path unless simple _prefix_values.each do |value| index = path.index(value) return _prefix_index[value] + ':' + path[value.length..-1] if index end return path end |
._setup_(base_uri = When::SourceURI) ⇒ void
本メソッドでマルチスレッド対応の管理変数の初期化を行っている。 このため、本メソッド自体はスレッドセーフでない。
This method returns an undefined value.
初期化
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/when_exe/parts/resource.rb', line 150 def _setup_(base_uri=When::SourceURI) super() @_prefix = { '_w' => base_uri + '/', '_p' => base_uri + 'Parts/', '_b' => base_uri + 'BasicTypes/', '_m' => base_uri + 'BasicTypes/M17n/', '_co' => base_uri + 'Coordinates/', '_l' => base_uri + 'Coordinates/Spatial?', '_v' => base_uri + 'V/', '_rs' => base_uri + 'RS/', '_ex' => base_uri + 'EX/', '_tm' => base_uri + 'TM/', '_e' => base_uri + 'TM/CalendarEra/', '_t' => base_uri + 'TimeStandard/', '_ep' => base_uri + 'Ephemeris/', '_c' => base_uri + 'CalendarTypes/', '_n' => base_uri + 'CalendarTypes/CalendarNote/', '_sc' => base_uri + 'Ephemeris/V50/' } @base_uri = base_uri @_prefix_values = @_prefix.values.sort.reverse @_prefix_index = @_prefix.invert end |
Instance Method Details
#[](iri) ⇒ When::parts::Resource
IRI または child の番号によるオブジェクト参照
479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 |
# File 'lib/when_exe/parts/resource.rb', line 479 def [](iri) case iri when Numeric return child[iri * 1] when String obj = self iri.split(/::/).each do |label| return obj.child if label == '*' if obj == Resource obj = Resource._instance(label) else case label when '' ; obj = Resource when '.' # obj = obj else ; obj = obj._pool[label.gsub(/%3A%3A/, '::')] end end raise ArgumentError, "IRI not found: #{iri}" unless obj end return obj else super(iri) #raise ArgumentError, "IRI not found: #{iri}" end end |
#^(other) ⇒ Enumerator
Enumerator 生成のダミー
642 643 644 |
# File 'lib/when_exe/parts/resource.rb', line 642 def ^(other) return nil end |
#each(*args, &block) ⇒ Enumerator
順次実行
653 654 655 656 657 |
# File 'lib/when_exe/parts/resource.rb', line 653 def each(*args, &block) enum = enum_for(*args) return enum unless block enum.each(&block) end |
#enum_for(direction = :forward) ⇒ Object Also known as: to_enum
オブジェクトを順に取り出す enumerator
@param [Symbol] direction 取り出す方向
[ :forward - 昇順 ]
[ :reverse - 降順 ]
631 632 633 |
# File 'lib/when_exe/parts/resource.rb', line 631 def enum_for(direction=:forward) Enumerator.new(self, direction) end |
#hierarchy(klass = self.class) ⇒ When::Parts::Resource
self を包含するオブジェクト階層
519 520 521 522 523 524 525 526 527 |
# File 'lib/when_exe/parts/resource.rb', line 519 def hierarchy(klass=self.class) hierarchy = [] parent = self while parent.kind_of?(klass) hierarchy << parent parent = parent.parent end hierarchy.reverse end |
#include?(other) ⇒ Boolean
self が other を包含するか
535 536 537 538 539 540 541 542 |
# File 'lib/when_exe/parts/resource.rb', line 535 def include?(other) c = other while c.kind_of?(Resource) return true if c.equal?(self) c = c.parent end return false end |
#included?(other) ⇒ Boolean
other が self を包含するか
550 551 552 |
# File 'lib/when_exe/parts/resource.rb', line 550 def included?(other) other.include?(self) end |
#iri ⇒ Object
オブジェクトの IRI
@return [Sring]
460 461 462 463 464 465 466 467 468 469 470 |
# File 'lib/when_exe/parts/resource.rb', line 460 def iri return @iri if @iri root = @_pool['..'] path = root.instance_of?(String) ? root : label.to_s path = path.gsub(/::/, '%3A%3A') if root.respond_to?(:iri) prefix = root.iri path = prefix + '::' + path if prefix end @iri = path end |
#leaf? ⇒ Boolean
オブジェクト包含階層の末端か?
583 584 585 |
# File 'lib/when_exe/parts/resource.rb', line 583 def leaf? !@child || (@child.length==0) end |
#m17n(source, namespace = nil, locale = nil, options = {}) ⇒ When::BasicTypes::M17n or Array<them>
When::BasicTypes::M17n の生成/参照
614 615 616 617 618 619 620 621 622 623 |
# File 'lib/when_exe/parts/resource.rb', line 614 def m17n(source, namespace=nil, locale=nil, ={}) case source when Array ; When::BasicTypes::M17n.new(source, namespace, locale, ) when When::BasicTypes::M17n ; source when String return self[$1] if source =~ /^\s*\[((\.{1,2}|::)+[^\]]+)\]/ When::BasicTypes::M17n.new(source, namespace, locale, ) else ; raise TypeError, "Invalid Type: #{source.class}" end end |
#map(&block) ⇒ Array Also known as: collect
map, collect の再定義
has-a 関係の子 Resource に対して map/collect を行う
667 668 669 |
# File 'lib/when_exe/parts/resource.rb', line 667 def map(&block) @child.map(&block) end |
#next ⇒ When::Parts::Resource Also known as: succ
次のオブジェクト
570 571 572 573 574 |
# File 'lib/when_exe/parts/resource.rb', line 570 def next c = self c = c.child[0] while c.child && c.child.size > 0 c._pool['.->'] end |
#parent ⇒ When::Parts::Resource
self を直接に包含するオブジェクト
509 510 511 |
# File 'lib/when_exe/parts/resource.rb', line 509 def parent @_pool['..'].kind_of?(Resource) ? @_pool['..'] : nil end |
#prev ⇒ When::Parts::Resource
前のオブジェクト
558 559 560 561 562 563 564 |
# File 'lib/when_exe/parts/resource.rb', line 558 def prev c = self c = c.child[0] while c.child && c.child.size > 0 c = c._pool['.<-'] c = c.child[-1] while c && c.child && c.child.size > 0 c end |
#registered? ⇒ Boolean
IRIが付与されているか?
593 594 595 596 597 598 599 600 601 |
# File 'lib/when_exe/parts/resource.rb', line 593 def registered? leaf = self while leaf._pool['..'].respond_to?(:_pool) root = leaf._pool['..'] return false unless leaf.equal?(root._pool[leaf.label]) leaf = root end Resource._pool.value?(leaf) end |