Class: When::TM::Period

Inherits:
GeometricPrimitive show all
Defined in:
lib/when_exe/tmobjects.rb

Overview

期間 - 一次元幾何プリミティブ

see gml schema

Constant Summary collapse

RELATIVE_POSITION =
{
  RelativePosition::Contains => {
    RelativePosition::Before   => RelativePosition::Overlaps,
    RelativePosition::EndedBy  => RelativePosition::EndedBy,
    RelativePosition::Contains => RelativePosition::Contains
  },
  RelativePosition::BegunBy => {
    RelativePosition::Before   => RelativePosition::Begins,
    RelativePosition::EndedBy  => RelativePosition::Equals,
    RelativePosition::Contains => RelativePosition::BegunBy
  },
  RelativePosition::After => {
    RelativePosition::Before   => RelativePosition::During,
    RelativePosition::EndedBy  => RelativePosition::Ends,
    RelativePosition::Contains => RelativePosition::OverlappedBy
  }
}

Constants included from Parts::Resource

Parts::Resource::ConstList, Parts::Resource::ConstTypes, Parts::Resource::IRIDecode, Parts::Resource::IRIDecodeTable, Parts::Resource::IRIEncode, Parts::Resource::IRIEncodeTable, Parts::Resource::IRIHeader, Parts::Resource::LabelProperty

Constants included from Namespace

Namespace::DC, Namespace::DCQ, Namespace::DCT, Namespace::FOAF, Namespace::OWL, Namespace::RDF, Namespace::RDFC, Namespace::RDFS, Namespace::RSS, Namespace::XSD

Instance Attribute Summary collapse

Attributes inherited from BasicTypes::Object

#label

Attributes included from Parts::Resource

#_pool, #child, #keys, #locale, #namespace

Instance Method Summary collapse

Methods included from Parts::Resource

#[], #^, _abbreviation_to_iri, _decode, _encode, _extract_prefix, _instance, _instantiate, _parse, _path_with_prefix, _replace_tags, _setup_, _setup_info, _simplify_path, base_uri, #each, #enum_for, #hierarchy, #include?, #included?, #iri, #leaf?, #m17n, #map, #parent, #registered?, root_dir

Methods included from Parts::Resource::Pool

#[], #[]=, #_pool, #_setup_, #pool_keys

Methods included from Parts::Resource::Synchronize

#synchronize

Constructor Details

#initialize(begun, ended) ⇒ Period

オブジェクトの生成

Parameters:

Raises:

  • (ArgumentError)


378
379
380
381
382
383
384
# File 'lib/when_exe/tmobjects.rb', line 378

def initialize(begun, ended)
  raise ArgumentError, 'Order mismatch: begun > ended' if begun > ended
  @begin = begun
  @end   = ended
  @begin.begun_by << self
  @end.ended_by   << self
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object (private)

Note:

When::TM::Period で定義されていないメソッドは 処理を @begin (type: When::TM::Instant) に委譲する

その他のメソッド



394
395
396
397
398
399
400
401
# File 'lib/when_exe/tmobjects.rb', line 394

def method_missing(name, *args, &block)
  self.class.module_eval %Q{
    def #{name}(*args, &block)
      @begin.send("#{name}", *args, &block)
    end
  } unless When::Parts::MethodCash.escape(name)
  @begin.send(name, *args, &block)
end

Instance Attribute Details

#beginWhen::TM::Instant (readonly)

この期間が始まる瞬間 (relation - Beginning)

Returns:



297
298
299
# File 'lib/when_exe/tmobjects.rb', line 297

def begin
  @begin
end

#endWhen::TM::Instant (readonly)

この期間が終わる瞬間 (relation - Ending)

Returns:



303
304
305
# File 'lib/when_exe/tmobjects.rb', line 303

def end
  @end
end

#topologyWhen::TM::Edge (readonly)

対応するエッジ (relation - Realization)

Returns:



309
310
311
# File 'lib/when_exe/tmobjects.rb', line 309

def topology
  @topology
end

Instance Method Details

#distance(other) ⇒ When::TM::Duration

他のWhen::TM::GeometricPrimitiveとの時間位置の差の絶対値

Parameters:

Returns:



325
326
327
328
329
330
331
332
333
334
335
336
# File 'lib/when_exe/tmobjects.rb', line 325

def distance(other)
  case other
  when Instant
    return other.distance(self)
  when Period
    verify = other.begin.position - self.end.position
    return verify if verify.sign >= 0
    return [self.begin.position - other.end.position, When::TM::PeriodDuration.new(0,When::DAY)].max
  else
    raise TypeError, "The right operand should be Instant or Period"
  end
end

#lengthWhen::TM::Duration

When::TM::GeometricPrimitive 自身の持続時間

Returns:



315
316
317
# File 'lib/when_exe/tmobjects.rb', line 315

def length()
  @length ||= @end - @begin
end

#relative_position(other) ⇒ When::TM::RelativePosition Also known as: relativePosition

他のPrimitiveとの相対的な時間位置

Parameters:

Returns:



344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
# File 'lib/when_exe/tmobjects.rb', line 344

def relative_position(other)
  case other
  when Instant
    verify = self.end.position <=> other.position
    return RelativePosition::Before   if verify <  0
    return RelativePosition::EndedBy  if verify == 0
    verify = self.begin.position <=> other.position
    return RelativePosition::Contains if verify <  0
    return RelativePosition::BegunBy  if verify == 0
    return RelativePosition::After
  when Period
    verify_b = relative_position(other.begin)
    case verify_b
    when RelativePosition::Before  ; return RelativePosition::Before
    when RelativePosition::EndedBy ; return RelativePosition::Meets
    end
    verify_e = relative_position(other.end)
    case verify_e
    when RelativePosition::BegunBy ; return RelativePosition::MetBy
    when RelativePosition::After   ; return RelativePosition::After
    else                           ; return RELATIVE_POSITION[verify_b][verify_e]
    end
  else
    raise TypeError, "The right operand should be Instant or Period"
  end
end