module Locd::Label

Static method namespace for dealing with labels.

Public Class Methods

compare(label_a, label_b) click to toggle source
# File lib/locd/label.rb, line 50
def self.compare label_a, label_b
  [label_a, label_b].
    map { |label| label.split( '.' ).reverse }.
    thru { |a, b| a <=> b }
end
regexp_for_glob(string, full: false, ignore_case: false) click to toggle source

Simple transformation of “glob-style” label patterns to {Regexp}.

**_Right now only handles the `*` wildcard!_**

@param [String] string

Glob-style pattern to search for in {Locd::Agent#label} strings.

@param [Boolean] full:

When `false`, the returned Regexp will match any part of label
strings.

When `true`, the generated Regexp will only match if `pattern` matches
entire label strings.

@param [Boolean] ignore_case:

Makes the Regexp case-insensitive.
# File lib/locd/label.rb, line 34
def self.regexp_for_glob string, full: false, ignore_case: false
  string.
    # Uncommon option: `-1` causes empty segments to be included, which
    # fixes the issue of `*` at start or end
    split( '*', -1 ).
    map( &Regexp.method( :escape ) ).
    join( '.*' ).
    thru { |regexp_string|
      # Add `\A` and `\z` caps if `exact` is set
      regexp_string = "\\A#{ regexp_string }\\z" if full
      
      Regexp.new regexp_string, ignore_case
    }
end
url_for(label, tld:, port: "http:// click to toggle source
# File lib/locd/label.rb, line 11
def self.url_for label, tld:, port:
  "http://#{ label }:#{ port }"
end