Class: Kiki::Key

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(namespace, delimiter, domain, identifier) ⇒ Key

Returns a new instance of Key.



8
9
10
11
12
13
# File 'lib/kiki/key.rb', line 8

def initialize(namespace, delimiter, domain, identifier)
  @namespace = namespace
  @delimiter = delimiter
  @domain = domain
  @identifier = identifier
end

Instance Attribute Details

#delimiterObject

Returns the value of attribute delimiter.



6
7
8
# File 'lib/kiki/key.rb', line 6

def delimiter
  @delimiter
end

#domainObject

Returns the value of attribute domain.



6
7
8
# File 'lib/kiki/key.rb', line 6

def domain
  @domain
end

#identifierObject

Returns the value of attribute identifier.



6
7
8
# File 'lib/kiki/key.rb', line 6

def identifier
  @identifier
end

#namespaceObject (readonly)

Returns the value of attribute namespace.



5
6
7
# File 'lib/kiki/key.rb', line 5

def namespace
  @namespace
end

Instance Method Details

#for(*args) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/kiki/key.rb', line 15

def for(*args)
  components = [@namespace, @domain] + args.collect do |arg|
    case arg
    when String, Numeric then arg
    else
      arg.respond_to?(@identifier) ? arg.send(@identifier) : arg.to_s
    end
  end

  components.compact.join(@delimiter)
end