Class: Trifle::Stats::Nocturnal::Key

Inherits:
Object
  • Object
show all
Defined in:
lib/trifle/stats/nocturnal/key.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key:, granularity: nil, at: nil) ⇒ Key

Returns a new instance of Key.



10
11
12
13
14
15
# File 'lib/trifle/stats/nocturnal/key.rb', line 10

def initialize(key:, granularity: nil, at: nil)
  @prefix = nil
  @key = key
  @granularity = granularity
  @at = at
end

Instance Attribute Details

#atObject (readonly)

Returns the value of attribute at.



7
8
9
# File 'lib/trifle/stats/nocturnal/key.rb', line 7

def at
  @at
end

#granularityObject (readonly)

Returns the value of attribute granularity.



7
8
9
# File 'lib/trifle/stats/nocturnal/key.rb', line 7

def granularity
  @granularity
end

#keyObject (readonly)

Returns the value of attribute key.



7
8
9
# File 'lib/trifle/stats/nocturnal/key.rb', line 7

def key
  @key
end

#prefixObject

Returns the value of attribute prefix.



8
9
10
# File 'lib/trifle/stats/nocturnal/key.rb', line 8

def prefix
  @prefix
end

Instance Method Details

#identifier(separator, mode = :full) ⇒ Object

Raises:

  • (ArgumentError)


21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/trifle/stats/nocturnal/key.rb', line 21

def identifier(separator, mode = :full)
  mode = normalize_join_mode(mode)

  return { key: key, granularity: granularity, at: at }.compact if mode == :separated

  raise ArgumentError, 'separator must be a String for joined identifiers' if separator.nil?

  if mode == :partial
    { key: partial_join(separator), at: at }.compact
  else
    { key: join(separator) }
  end
end

#join(separator) ⇒ Object



17
18
19
# File 'lib/trifle/stats/nocturnal/key.rb', line 17

def join(separator)
  [prefix, key, granularity, at&.to_i].compact.join(separator)
end