Class: Keytar::Key

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

Overview

cannot change :order can change :unique

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Key

Returns a new instance of Key.



17
18
19
20
21
22
23
# File 'lib/keytar.rb', line 17

def initialize(options = {})
  options[:name]  = options.delete(:name).to_s.gsub(/(^key$|_key$)/, '')
  self.delimiter  = options.delete(:delimiter)
  self.order      = options.delete(:order)
  self.key_case   = options.delete(:key_case)
  self.options    = options
end

Instance Attribute Details

#delimiterObject

Returns the value of attribute delimiter.



16
17
18
# File 'lib/keytar.rb', line 16

def delimiter
  @delimiter
end

#key_caseObject

Returns the value of attribute key_case.



16
17
18
# File 'lib/keytar.rb', line 16

def key_case
  @key_case
end

#optionsObject

Returns the value of attribute options.



16
17
18
# File 'lib/keytar.rb', line 16

def options
  @options
end

#orderObject

Returns the value of attribute order.



16
17
18
# File 'lib/keytar.rb', line 16

def order
  @order
end

Class Method Details

.build(options = {}) ⇒ Object



35
36
37
# File 'lib/keytar.rb', line 35

def self.build(options = {})
  self.new(options).to_s
end

Instance Method Details

#key_arrayObject



25
26
27
# File 'lib/keytar.rb', line 25

def key_array
  order.map {|key| options[key]}.flatten.compact.map(&:to_s)
end

#to_sObject



29
30
31
32
33
# File 'lib/keytar.rb', line 29

def to_s
  key = key_array.join(delimiter)
  key = key.send key_case if key_case.present? && key.respond_to?(key_case)
  key
end