Class: Dominion::DomainSuffixRule

Inherits:
Object
  • Object
show all
Defined in:
lib/dominion/domain_suffix_rule.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(s) ⇒ DomainSuffixRule

Returns a new instance of DomainSuffixRule.



8
9
10
11
12
13
# File 'lib/dominion/domain_suffix_rule.rb', line 8

def initialize(s)
  @string    = s.strip.gsub(/\A\.|\.\z/, '')
  @labels    = @string.split(/\A!|\./).reverse
  @exception = @labels.last.empty? and @labels.pop
  @length    = @labels.length - (@exception ? 1 : 0)
end

Instance Attribute Details

#exceptionObject (readonly)

Returns the value of attribute exception.



6
7
8
# File 'lib/dominion/domain_suffix_rule.rb', line 6

def exception
  @exception
end

#labelsObject (readonly)

Returns the value of attribute labels.



6
7
8
# File 'lib/dominion/domain_suffix_rule.rb', line 6

def labels
  @labels
end

#lengthObject (readonly)

Returns the value of attribute length.



6
7
8
# File 'lib/dominion/domain_suffix_rule.rb', line 6

def length
  @length
end

Instance Method Details

#=~(domain) ⇒ Object

match against a domain name. the domain must be an instance of DomainName



16
17
18
# File 'lib/dominion/domain_suffix_rule.rb', line 16

def =~(domain)
  labels.zip(domain.labels).all? { |r, d| ["*", d].include? r }
end

#inspectObject



20
21
22
# File 'lib/dominion/domain_suffix_rule.rb', line 20

def inspect
  @string
end