Class: Cogger::Tag
- Inherits:
-
Data
- Object
- Data
- Cogger::Tag
- Defined in:
- lib/cogger/tag.rb
Overview
Models a tag which may consist of an array and/or hash.
Instance Attribute Summary collapse
-
#exclusions ⇒ Object
readonly
Returns the value of attribute exclusions.
-
#pairs ⇒ Object
readonly
Returns the value of attribute pairs.
-
#singles ⇒ Object
readonly
Returns the value of attribute singles.
Class Method Summary collapse
Instance Method Summary collapse
- #empty? ⇒ Boolean
-
#initialize(singles: [], pairs: {}, exclusions: %w[id level at message]) ⇒ Tag
constructor
A new instance of Tag.
- #to_h ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(singles: [], pairs: {}, exclusions: %w[id level at message]) ⇒ Tag
Returns a new instance of Tag.
22 23 24 25 26 |
# File 'lib/cogger/tag.rb', line 22 def initialize singles: [], pairs: {}, exclusions: %w[id level at message] filtered_pairs = pairs.reject { |key, _| exclusions.include? key.to_s } super singles:, pairs: filtered_pairs, exclusions: end |
Instance Attribute Details
#exclusions ⇒ Object (readonly)
Returns the value of attribute exclusions
8 9 10 |
# File 'lib/cogger/tag.rb', line 8 def exclusions @exclusions end |
#pairs ⇒ Object (readonly)
Returns the value of attribute pairs
8 9 10 |
# File 'lib/cogger/tag.rb', line 8 def pairs @pairs end |
#singles ⇒ Object (readonly)
Returns the value of attribute singles
8 9 10 |
# File 'lib/cogger/tag.rb', line 8 def singles @singles end |
Class Method Details
.for(*bag) ⇒ Object
11 |
# File 'lib/cogger/tag.rb', line 11 def self.for(*bag) = new(**reduce(bag)) |
Instance Method Details
#empty? ⇒ Boolean
28 |
# File 'lib/cogger/tag.rb', line 28 def empty? = singles.empty? && pairs.empty? |
#to_h ⇒ Object
30 |
# File 'lib/cogger/tag.rb', line 30 def to_h = empty? ? Core::EMPTY_HASH : {tags: singles.to_a, **pairs}.tap(&:compress!) |
#to_s ⇒ Object
32 |
# File 'lib/cogger/tag.rb', line 32 def to_s = empty? ? Core::EMPTY_STRING : "#{format_singles} #{format_pairs}".tap(&:strip!) |