Class: Pebblebed::Labels

Inherits:
Object
  • Object
show all
Defined in:
lib/pebblebed/labels.rb

Constant Summary collapse

NO_MARKER =
Class.new

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options = {})
  @path = path
  @base_path = path.split('.').select {|label| Uid.valid_label?(label)}.join('.')
  @wildcard = !!Uid.wildcard_path?(path)
  @prefix = options.fetch(:prefix) { 'label' }
  @suffix = options.fetch(:suffix) { nil }
  @stop = options.fetch(:stop) { NO_MARKER }
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



6
7
8
# File 'lib/pebblebed/labels.rb', line 6

def path
  @path
end

#prefixObject (readonly)

Returns the value of attribute prefix.



6
7
8
# File 'lib/pebblebed/labels.rb', line 6

def prefix
  @prefix
end

#stopObject (readonly)

Returns the value of attribute stop.



6
7
8
# File 'lib/pebblebed/labels.rb', line 6

def stop
  @stop
end

#suffixObject (readonly)

Returns the value of attribute suffix.



6
7
8
# File 'lib/pebblebed/labels.rb', line 6

def suffix
  @suffix
end

Instance Method Details

#expandedObject



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/pebblebed/labels.rb', line 24

def expanded
  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

#nextObject



16
17
18
# File 'lib/pebblebed/labels.rb', line 16

def next
  label(expanded.length)
end

#use_stop_marker?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/pebblebed/labels.rb', line 42

def use_stop_marker?
  stop != NO_MARKER
end

#wildcard?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/pebblebed/labels.rb', line 20

def wildcard?
  @wildcard
end