Class: Trifle::Stats::Nocturnal::Key
- Inherits:
-
Object
- Object
- Trifle::Stats::Nocturnal::Key
- Defined in:
- lib/trifle/stats/nocturnal/key.rb
Instance Attribute Summary collapse
-
#at ⇒ Object
readonly
Returns the value of attribute at.
-
#granularity ⇒ Object
readonly
Returns the value of attribute granularity.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#prefix ⇒ Object
Returns the value of attribute prefix.
Instance Method Summary collapse
- #identifier(separator, mode = :full) ⇒ Object
-
#initialize(key:, granularity: nil, at: nil) ⇒ Key
constructor
A new instance of Key.
- #join(separator) ⇒ Object
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
#at ⇒ Object (readonly)
Returns the value of attribute at.
7 8 9 |
# File 'lib/trifle/stats/nocturnal/key.rb', line 7 def at @at end |
#granularity ⇒ Object (readonly)
Returns the value of attribute granularity.
7 8 9 |
# File 'lib/trifle/stats/nocturnal/key.rb', line 7 def granularity @granularity end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
7 8 9 |
# File 'lib/trifle/stats/nocturnal/key.rb', line 7 def key @key end |
#prefix ⇒ Object
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
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 |