Module: Locd::Label
- Defined in:
- lib/locd/label.rb
Overview
Static method namespace for dealing with labels.
Class Method Summary collapse
- .compare(label_a, label_b) ⇒ Object
-
.regexp_for_glob(string, full: false, ignore_case: false) ⇒ Object
Simple transformation of "glob-style" label patterns to Regexp.
- .url_for(label, tld:, port:) ⇒ Object
Class Method Details
.compare(label_a, label_b) ⇒ Object
50 51 52 53 54 |
# 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) ⇒ Object
Simple transformation of "glob-style" label patterns to Regexp.
Right now only handles the * wildcard!
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# 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:) ⇒ Object
11 12 13 |
# File 'lib/locd/label.rb', line 11 def self.url_for label, tld:, port: "http://#{ label }:#{ port }" end |