Class: Pebblebed::Labels
- Inherits:
-
Object
- Object
- Pebblebed::Labels
- Defined in:
- lib/pebblebed/labels.rb
Constant Summary collapse
- NO_MARKER =
Class.new
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
-
#stop ⇒ Object
readonly
Returns the value of attribute stop.
-
#suffix ⇒ Object
readonly
Returns the value of attribute suffix.
Instance Method Summary collapse
- #expanded ⇒ Object
-
#initialize(path, options = {}) ⇒ Labels
constructor
A new instance of Labels.
- #label(i) ⇒ Object
- #next ⇒ Object
- #use_stop_marker? ⇒ Boolean
- #wildcard? ⇒ Boolean
Constructor Details
#initialize(path, options = {}) ⇒ Labels
Returns a new instance of Labels.
7 8 9 10 11 12 13 14 |
# File 'lib/pebblebed/labels.rb', line 7 def initialize(path, = {}) @path = path @base_path = path.split('.').select {|label| Uid.valid_label?(label)}.join('.') @wildcard = !!Uid.wildcard_path?(path) @prefix = .fetch(:prefix) { 'label' } @suffix = .fetch(:suffix) { nil } @stop = .fetch(:stop) { NO_MARKER } end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
6 7 8 |
# File 'lib/pebblebed/labels.rb', line 6 def path @path end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
6 7 8 |
# File 'lib/pebblebed/labels.rb', line 6 def prefix @prefix end |
#stop ⇒ Object (readonly)
Returns the value of attribute stop.
6 7 8 |
# File 'lib/pebblebed/labels.rb', line 6 def stop @stop end |
#suffix ⇒ Object (readonly)
Returns the value of attribute suffix.
6 7 8 |
# File 'lib/pebblebed/labels.rb', line 6 def suffix @suffix end |
Instance Method Details
#expanded ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/pebblebed/labels.rb', line 24 def unless @expanded values = {} @base_path.split('.').each_with_index do |label, i| values[label(i)] = label end if use_stop_marker? values[label(values.length)] = stop end @expanded = values end @expanded end |
#label(i) ⇒ Object
38 39 40 |
# File 'lib/pebblebed/labels.rb', line 38 def label(i) [prefix, i, suffix].compact.join('_') end |
#next ⇒ Object
16 17 18 |
# File 'lib/pebblebed/labels.rb', line 16 def next label(.length) end |
#use_stop_marker? ⇒ Boolean
42 43 44 |
# File 'lib/pebblebed/labels.rb', line 42 def use_stop_marker? stop != NO_MARKER end |
#wildcard? ⇒ Boolean
20 21 22 |
# File 'lib/pebblebed/labels.rb', line 20 def wildcard? @wildcard end |