Class: MachineTag::Tag
- Inherits:
-
String
- Object
- String
- MachineTag::Tag
- Defined in:
- lib/machine_tag/tag.rb
Overview
A tag which can be a machine tag.
Instance Attribute Summary collapse
-
#namespace ⇒ String?
readonly
The namespace portion of the machine tag,
nil
if the tag is not a machine tag. -
#namespace_and_predicate ⇒ String?
readonly
The namespace and predicate portion of the machine tag,
nil
if the tag is not a machine tag. -
#predicate ⇒ String?
readonly
The predicate portion of the machine tag,
nil
if the tag is not a machine tag. -
#value ⇒ String?
readonly
The value portion of the machine tag,
nil
if the tag is not a machine tag.
Class Method Summary collapse
-
.machine_tag(namespace, predicate, value) ⇒ Tag
Creates a machine tag from a given namespace, predicate, and value.
Instance Method Summary collapse
-
#initialize(str) ⇒ Tag
constructor
Creates a tag object which can be a machine tag.
-
#machine_tag? ⇒ Boolean
Returns whether this tag is a machine tag or not.
Constructor Details
#initialize(str) ⇒ Tag
Creates a tag object which can be a machine tag.
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/machine_tag/tag.rb', line 76 def initialize(str) super if match = self.match(MACHINE_TAG) @namespace_and_predicate = match[:namespace_and_predicate] @namespace = match[:namespace] @predicate = match[:predicate] @value = match[:value] @value = $1 if @value =~ /^"(.*)"$/ end end |
Instance Attribute Details
#namespace ⇒ String? (readonly)
The namespace portion of the machine tag, nil
if the tag is not a machine tag
51 52 53 |
# File 'lib/machine_tag/tag.rb', line 51 def namespace @namespace end |
#namespace_and_predicate ⇒ String? (readonly)
The namespace and predicate portion of the machine tag, nil
if the tag is not a machine tag
64 65 66 |
# File 'lib/machine_tag/tag.rb', line 64 def namespace_and_predicate @namespace_and_predicate end |
#predicate ⇒ String? (readonly)
The predicate portion of the machine tag, nil
if the tag is not a machine tag
57 58 59 |
# File 'lib/machine_tag/tag.rb', line 57 def predicate @predicate end |
#value ⇒ String? (readonly)
The value portion of the machine tag, nil
if the tag is not a machine tag
70 71 72 |
# File 'lib/machine_tag/tag.rb', line 70 def value @value end |
Class Method Details
.machine_tag(namespace, predicate, value) ⇒ Tag
Creates a machine tag from a given namespace, predicate, and value.
97 98 99 100 101 102 |
# File 'lib/machine_tag/tag.rb', line 97 def self.machine_tag(namespace, predicate, value) raise ArgumentError, "Invalid machine tag namespace: #{namespace.inspect}" unless namespace =~ /^#{PREFIX}$/ raise ArgumentError, "Invalid machine tag predicate: #{predicate.inspect}" unless predicate =~ /^#{PREFIX}$/ new("#{namespace}:#{predicate}=#{value}") end |
Instance Method Details
#machine_tag? ⇒ Boolean
Returns whether this tag is a machine tag or not.
108 109 110 |
# File 'lib/machine_tag/tag.rb', line 108 def machine_tag? !!namespace end |