Class: OpenPGP::Packet::UserID

Inherits:
OpenPGP::Packet show all
Defined in:
lib/openpgp/packet.rb

Overview

OpenPGP User ID packet (tag 13).

Instance Attribute Summary collapse

Attributes inherited from OpenPGP::Packet

#data, #size, #tag

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from OpenPGP::Packet

#body, for, #initialize, parse, parse_new_format, parse_old_format, tag

Constructor Details

This class inherits a constructor from OpenPGP::Packet

Instance Attribute Details

#commentObject

Returns the value of attribute comment.


404
405
406
# File 'lib/openpgp/packet.rb', line 404

def comment
  @comment
end

#emailObject

Returns the value of attribute email.


404
405
406
# File 'lib/openpgp/packet.rb', line 404

def email
  @email
end

#nameObject

Returns the value of attribute name.


404
405
406
# File 'lib/openpgp/packet.rb', line 404

def name
  @name
end

Class Method Details

.parse_body(body, options = {}) ⇒ Object

[View source]

406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
# File 'lib/openpgp/packet.rb', line 406

def self.parse_body(body, options = {})
  case body.read
    # User IDs of the form: "name (comment) <email>"
    when /^([^\(]+)\(([^\)]+)\)\s+<([^>]+)>$/
      self.new(:name => $1.strip, :comment => $2.strip, :email => $3.strip)
    # User IDs of the form: "name <email>"
    when /^([^<]+)\s+<([^>]+)>$/
      self.new(:name => $1.strip, :comment => nil, :email => $2.strip)
    # User IDs of the form: "name"
    when /^([^<]+)$/
      self.new(:name => $1.strip, :comment => nil, :email => nil)
    # User IDs of the form: "<email>"
    when /^<([^>]+)>$/
      self.new(:name => nil, :comment => nil, :email => $1.strip)
    else
      self.new(:name => nil, :comment => nil, :email => nil)
  end
end

Instance Method Details

#to_sObject

[View source]

429
430
431
432
433
434
435
# File 'lib/openpgp/packet.rb', line 429

def to_s
  text = []
  text << name if name
  text << "(#{comment})" if comment
  text << "<#{email}>" if email
  text.join(' ')
end

#write_body(buffer) ⇒ Object

[View source]

425
426
427
# File 'lib/openpgp/packet.rb', line 425

def write_body(buffer)
  buffer.write(to_s)
end