Class: AIXM::Feature::Address

Inherits:
AIXM::Feature show all
Includes:
Association, Memoize
Defined in:
lib/aixm/feature/address.rb

Overview

Address or similar means to contact an entity.

Cheat Sheet in Pseudo Code:

address = AIXM.address(
  source: String or nil
  type: TYPES
  address: String
)
service.remarks = String or nil

Constant Summary collapse

TYPES =
{
  POST: :postal_address,
  PHONE: :phone,
  'PHONE-MET': :weather_phone,
  FAX: :fax,
  TLX: :telex,
  SITA: :sita,
  AFS: :aeronautical_fixed_service_address,
  EMAIL: :email,
  URL: :url,
  'URL-CAM': :webcam,
  'URL-MET': :weather_url,
  RADIO: :radio_frequency,
  OTHER: :other   # specify in remarks
}

Constants inherited from AIXM::Feature

REGION_RE

Instance Attribute Summary collapse

Attributes inherited from AIXM::Feature

#region, #source

Instance Method Summary collapse

Methods included from Memoize

cache, included, method

Methods included from Association

included

Methods inherited from AIXM::Feature

#==

Constructor Details

#initialize(source: nil, region: nil, type:, address:) ⇒ Address

Returns a new instance of Address.


52
53
54
55
# File 'lib/aixm/feature/address.rb', line 52

def initialize(source: nil, region: nil, type:, address:)
  super(source: source, region: region)
  self.type, self.address = type, address
end

Instance Attribute Details

#addressString

Returns postal address, phone number, radio frequency etc.

Returns:

  • (String)

    postal address, phone number, radio frequency etc


47
48
49
# File 'lib/aixm/feature/address.rb', line 47

def address
  @address
end

#remarksString?

Returns free text remarks.

Returns:

  • (String, nil)

    free text remarks


50
51
52
# File 'lib/aixm/feature/address.rb', line 50

def remarks
  @remarks
end

#typeSymbol

Returns type of address (see TYPES).

Returns:

  • (Symbol)

    type of address (see TYPES)


44
45
46
# File 'lib/aixm/feature/address.rb', line 44

def type
  @type
end

Instance Method Details

#addressableAIXM::Feature

Returns addressable feature.

Returns:


41
# File 'lib/aixm/feature/address.rb', line 41

belongs_to :addressable

#inspectString

Returns:

  • (String)

58
59
60
# File 'lib/aixm/feature/address.rb', line 58

def inspect
  %Q(#<#{self.class} type=#{type.inspect}>)
end

#to_uid(as:, sequence:) ⇒ String

Returns UID markup.

Returns:

  • (String)

    UID markup


76
77
78
79
80
81
82
83
# File 'lib/aixm/feature/address.rb', line 76

def to_uid(as:, sequence:)
  builder = Builder::XmlMarkup.new(indent: 2)
  builder.tag!(as) do |tag|
    tag << addressable.to_uid.indent(2) if addressable
    tag.codeType(TYPES.key(type).to_s.then_if(AIXM.aixm?) { _1.sub(/-\w+$/, '') })
    tag.noSeq(sequence)
  end
end

#to_xml(as:, sequence:) ⇒ String

Returns AIXM or OFMX markup.

Returns:

  • (String)

    AIXM or OFMX markup


87
88
89
90
91
92
93
94
95
# File 'lib/aixm/feature/address.rb', line 87

def to_xml(as:, sequence:)
  builder = Builder::XmlMarkup.new(indent: 2)
  builder.comment! ["Address: #{TYPES.key(type)}", addressable&.id].compact.join(' for ')
  builder.tag!(as, { source: (source if AIXM.ofmx?) }.compact) do |tag|
    tag << to_uid(as: :"#{as}Uid", sequence: sequence).indent(2)
    tag.txtAddress(address)
    tag.txtRmk(remarks) if remarks
  end
end