Class: OpenPGP::Packet::UserID

Inherits:
  • Object
show all
Defined in:
lib/openpgp/packet.rb

Overview

OpenPGP User ID packet (tag 13).

See Also:

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from

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

Constructor Details

This class inherits a constructor from OpenPGP::Packet

Instance Attribute Details

- (Object) comment

Returns the value of attribute comment



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

def comment
  @comment
end

- (Object) email

Returns the value of attribute email



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

def 
  @email
end

- (Object) name

Returns the value of attribute name



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

def name
  @name
end

Class Method Details

+ (Object) parse_body(body, options = {})



426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
# File 'lib/openpgp/packet.rb', line 426

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

- (Object) to_s



449
450
451
452
453
454
455
# File 'lib/openpgp/packet.rb', line 449

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

- (Object) write_body(buffer)



445
446
447
# File 'lib/openpgp/packet.rb', line 445

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