Module: Sourcerer::Yaml::TagUtils
- Defined in:
- lib/sourcerer/yaml.rb
Overview
Utility methods for working with YAML-sourced data adorned with tags
Class Method Summary collapse
-
.detag(value) ⇒ Object
Extracts the original value from a tagged data structure.
-
.tag?(value, tag) ⇒ Boolean
Checks if a value has a specific tag.
-
.tag_of(value) ⇒ String?
Retrieves the tag from a tagged data structure.
Class Method Details
.detag(value) ⇒ Object
Extracts the original value from a tagged data structure.
124 125 126 |
# File 'lib/sourcerer/yaml.rb', line 124 def self.detag value value.is_a?(Hash) && value.key?('value') ? value['value'] : value end |
.tag?(value, tag) ⇒ Boolean
Checks if a value has a specific tag.
141 142 143 |
# File 'lib/sourcerer/yaml.rb', line 141 def self.tag? value, tag tag_of(value)&.to_s == tag.to_s end |
.tag_of(value) ⇒ String?
Retrieves the tag from a tagged data structure.
132 133 134 |
# File 'lib/sourcerer/yaml.rb', line 132 def self.tag_of value value.is_a?(Hash) ? value['__tag__'] : nil end |