Class: TsipParser::Address

Inherits:
Object
  • Object
show all
Defined in:
lib/tsip_parser/address.rb

Overview

‘TsipParser::Address` wraps `tsip_parser::Address` via TypedData. Ruby side memoizes the embedded URI, display name, and params Hash so mutations (`addr.tag = “x”`, `addr.uri = Uri.parse(…)`, …) persist across reads and are reflected in `to_s`.

Instance Method Summary collapse

Instance Method Details

#append_to(buf) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/tsip_parser/address.rb', line 52

def append_to(buf)
  dn = display_name
  buf << '"' << dn << '" ' if dn
  buf << "<"
  u = uri
  u.append_to(buf) if u
  buf << ">"
  params.each do |k, v|
    buf << ";" << k
    vs = v.to_s
    buf << "=" << vs unless vs.empty?
  end
  buf
end

#display_nameObject



9
10
11
12
# File 'lib/tsip_parser/address.rb', line 9

def display_name
  return @display_name if defined?(@display_name)
  @display_name = _rust_display_name
end

#display_name=(v) ⇒ Object



14
15
16
# File 'lib/tsip_parser/address.rb', line 14

def display_name=(v)
  @display_name = v
end

#paramsObject



27
28
29
30
# File 'lib/tsip_parser/address.rb', line 27

def params
  return @params if defined?(@params)
  @params = _rust_params
end

#tagObject



32
33
34
35
36
37
38
39
# File 'lib/tsip_parser/address.rb', line 32

def tag
  # Fast path: if nobody has materialized @params yet, read directly
  # from the Rust Vec. Avoids building the whole Hash just to look up
  # one key — which is the common case (parsed Contact/To/From headers
  # are typically queried for tag and then dropped).
  return _rust_tag unless defined?(@params)
  @params["tag"]
end

#tag=(v) ⇒ Object



41
42
43
# File 'lib/tsip_parser/address.rb', line 41

def tag=(v)
  params["tag"] = v
end

#to_sObject



45
46
47
48
49
50
# File 'lib/tsip_parser/address.rb', line 45

def to_s
  return _rust_to_s unless defined?(@params) || defined?(@display_name) || defined?(@uri)
  out = +""
  append_to(out)
  out
end

#uriObject



18
19
20
21
# File 'lib/tsip_parser/address.rb', line 18

def uri
  return @uri if defined?(@uri)
  @uri = _rust_uri
end

#uri=(v) ⇒ Object



23
24
25
# File 'lib/tsip_parser/address.rb', line 23

def uri=(v)
  @uri = v
end