class Locd::Pattern::Label

A {Locd::Pattern} that matches against {Locd::Agent} labels with “glob-style” matching (like the [lunchy](rubygems.org/gems/lunchy) gem).

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

@see Locd::Label.regexp_for_glob

Attributes

regexp[R]

Label {Regexp} used by {#match?}

@return [Regexp]

string[R]

TODO document `string` attribute.

@return [attr_type]

Public Class Methods

new(source, full: false, ignore_case: false) click to toggle source

Instantiate a new `Locd::Pattern::Label`.

@param [String] source

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

@param [Boolean] full:

When `true`, pattern must match entire label.

When `false` (default), may match any portion.

@param [Boolean] ignore_case:

Perform case-insensitive matching.
Calls superclass method Locd::Pattern::new
# File lib/locd/pattern.rb, line 137
def initialize source, full: false, ignore_case: false
  super source
  @regexp = Locd::Label.regexp_for_glob source,
                                        full: full,
                                        ignore_case: ignore_case
end

Public Instance Methods

match?(agent) click to toggle source

See if this patten matches an agent.

@param [Locd::Agent] agent

Agent to test against.

@return [Boolean]

`true` if this pattern matches the `agent` {Locd::Agent#label}.
# File lib/locd/pattern.rb, line 153
def match? agent
  agent.label =~ regexp
end