Class: Pebbles::Uid::Labels
- Inherits:
-
Object
- Object
- Pebbles::Uid::Labels
- Includes:
- Enumerable
- Defined in:
- lib/pebbles-uid/labels.rb
Direct Known Subclasses
Constant Summary collapse
- NO_MARKER =
Class.new
Instance Attribute Summary collapse
-
#max_depth ⇒ Object
readonly
Returns the value of attribute max_depth.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#stop ⇒ Object
readonly
Returns the value of attribute stop.
-
#suffix ⇒ Object
readonly
Returns the value of attribute suffix.
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Instance Method Summary collapse
- #ambiguous? ⇒ Boolean
- #child_of?(other) ⇒ Boolean
- #conditions ⇒ Object
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(*values) ⇒ Labels
constructor
A new instance of Labels.
- #next_label ⇒ Object
- #parent_of?(other) ⇒ Boolean
- #size ⇒ Object
- #tail ⇒ Object
- #to_hash ⇒ Object
- #to_s ⇒ Object (also: #value)
- #use_stop_marker? ⇒ Boolean
- #valid_with?(pattern) ⇒ Boolean
- #wildcard? ⇒ Boolean
Constructor Details
#initialize(*values) ⇒ Labels
Returns a new instance of Labels.
9 10 11 12 13 14 15 16 17 |
# File 'lib/pebbles-uid/labels.rb', line 9 def initialize(*values) = values.pop if values.last.is_a?(Hash) ||= {} @values = values.flatten.compact.map {|v| v.split('.') }.flatten @name = [:name] @suffix = [:suffix] @stop = .fetch(:stop) { NO_MARKER } @max_depth = [:max_depth] end |
Instance Attribute Details
#max_depth ⇒ Object (readonly)
Returns the value of attribute max_depth.
8 9 10 |
# File 'lib/pebbles-uid/labels.rb', line 8 def max_depth @max_depth end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/pebbles-uid/labels.rb', line 8 def name @name end |
#stop ⇒ Object (readonly)
Returns the value of attribute stop.
8 9 10 |
# File 'lib/pebbles-uid/labels.rb', line 8 def stop @stop end |
#suffix ⇒ Object (readonly)
Returns the value of attribute suffix.
8 9 10 |
# File 'lib/pebbles-uid/labels.rb', line 8 def suffix @suffix end |
#values ⇒ Object (readonly)
Returns the value of attribute values.
8 9 10 |
# File 'lib/pebbles-uid/labels.rb', line 8 def values @values end |
Instance Method Details
#ambiguous? ⇒ Boolean
46 47 48 |
# File 'lib/pebbles-uid/labels.rb', line 46 def ambiguous? value == '*' || values.empty? || wildcard? end |
#child_of?(other) ⇒ Boolean
36 37 38 39 40 41 42 43 44 |
# File 'lib/pebbles-uid/labels.rb', line 36 def child_of?(other) child = true other.values.each_with_index do |label, i| if label != values[i] child = false end end child && other.size != size end |
#conditions ⇒ Object
79 80 81 82 83 84 85 86 |
# File 'lib/pebbles-uid/labels.rb', line 79 def conditions unless @conditions = {:name => name, :suffix => suffix} .merge!(:stop => stop) if use_stop_marker? @conditions = Conditions.new(values, ) end @conditions end |
#each(&block) ⇒ Object
19 20 21 |
# File 'lib/pebbles-uid/labels.rb', line 19 def each(&block) values.each {|value| yield value} end |
#empty? ⇒ Boolean
63 64 65 |
# File 'lib/pebbles-uid/labels.rb', line 63 def empty? values.empty? end |
#next_label ⇒ Object
75 76 77 |
# File 'lib/pebbles-uid/labels.rb', line 75 def next_label conditions.next end |
#parent_of?(other) ⇒ Boolean
27 28 29 30 31 32 33 34 |
# File 'lib/pebbles-uid/labels.rb', line 27 def parent_of?(other) return false if values == other.values parent = true values.each_with_index do |value, i| parent = false unless value == other.values[i] end parent end |
#size ⇒ Object
54 55 56 |
# File 'lib/pebbles-uid/labels.rb', line 54 def size values.size end |
#tail ⇒ Object
23 24 25 |
# File 'lib/pebbles-uid/labels.rb', line 23 def tail values[1..-1] end |
#to_hash ⇒ Object
71 72 73 |
# File 'lib/pebbles-uid/labels.rb', line 71 def to_hash conditions.to_hash end |
#to_s ⇒ Object Also known as: value
58 59 60 |
# File 'lib/pebbles-uid/labels.rb', line 58 def to_s values.join('.') end |
#use_stop_marker? ⇒ Boolean
88 89 90 |
# File 'lib/pebbles-uid/labels.rb', line 88 def use_stop_marker? stop != NO_MARKER && !(values.size == max_depth) end |
#valid_with?(pattern) ⇒ Boolean
50 51 52 |
# File 'lib/pebbles-uid/labels.rb', line 50 def valid_with?(pattern) !empty? && values.all? {|value| value[pattern] } end |
#wildcard? ⇒ Boolean
67 68 69 |
# File 'lib/pebbles-uid/labels.rb', line 67 def wildcard? !!(value =~ /[\*\|\^]/) end |