Class: AuthorizedKeys::Key

Inherits:
Object
  • Object
show all
Defined in:
lib/authorized_keys/key.rb

Defined Under Namespace

Modules: Components

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key_string) ⇒ Key

Returns a new instance of Key.

Raises:



16
17
18
19
20
21
22
# File 'lib/authorized_keys/key.rb', line 16

def initialize(key_string)
  options, self.content, self.comment = *Components.extract(key_string)

  raise BadKeyError.new(key_string) unless self.content

  self.options = options.split(/,/)
end

Instance Attribute Details

#commentObject

Returns the value of attribute comment.



14
15
16
# File 'lib/authorized_keys/key.rb', line 14

def comment
  @comment
end

#contentObject

Returns the value of attribute content.



14
15
16
# File 'lib/authorized_keys/key.rb', line 14

def content
  @content
end

#optionsObject

Returns the value of attribute options.



14
15
16
# File 'lib/authorized_keys/key.rb', line 14

def options
  @options
end

Instance Method Details

#==(key) ⇒ Object



29
30
31
32
# File 'lib/authorized_keys/key.rb', line 29

def ==(key)
  key = self.class.new(key) if key.is_a?(String)
  content == key.content
end

#to_sObject



24
25
26
27
# File 'lib/authorized_keys/key.rb', line 24

def to_s
  options = self.options.join(",") unless self.options.empty?
  [options, content, comment].compact.join(" ")
end