Class: Skeevy::Cutters::StandardKey

Inherits:
Object
  • Object
show all
Includes:
Skeevy::Cutter
Defined in:
lib/skeevy/cutters/standard_key.rb

Instance Attribute Summary

Attributes included from Skeevy::Cutter

#delimiter, #instance, #prefix

Instance Method Summary collapse

Methods included from Skeevy::Cutter

#initialize

Instance Method Details

#cut(hash:, ns:, object: nil) ⇒ Object

Raises:

  • (ArgumentError)


6
7
8
9
10
11
12
13
14
15
16
# File 'lib/skeevy/cutters/standard_key.rb', line 6

def cut(hash:, ns:, object: nil)
  object ||= ''
  hash   ||= ''
  ns     ||= ''
  raise ArgumentError, "Hash and namespace may not be blank" if hash.empty? || ns.empty?
  raise ArgumentError, "#{object} contains an instance of delimiter: #{@delimiter}" if object.include?(@delimiter)
  prefix ="#{@prefix}#{@delimiter}" unless @prefix.nil?
  key = "#{ns}#{@delimiter}#{hash}"
  suffix = "#{@delimiter}#{object}" unless object == ''
  "#{prefix}#{key}#{suffix}"
end