Class: Coppertone::Directive
- Inherits:
-
Object
- Object
- Coppertone::Directive
- Defined in:
- lib/coppertone/directive.rb
Overview
Instances of this class represent directive terms, as defined by the SPF specification (see section 4.6.1).
Constant Summary collapse
- DIRECTIVE_REGEXP =
/\A([+\-~?]?)([a-zA-Z0-9]*)((:?)\S*)\z/.freeze
Instance Attribute Summary collapse
-
#mechanism ⇒ Object
readonly
Returns the value of attribute mechanism.
-
#qualifier ⇒ Object
readonly
Returns the value of attribute qualifier.
Class Method Summary collapse
Instance Method Summary collapse
- #all? ⇒ Boolean
- #evaluate(context, options) ⇒ Object
-
#initialize(qualifier, mechanism) ⇒ Directive
constructor
A new instance of Directive.
- #target_domain ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(qualifier, mechanism) ⇒ Directive
Returns a new instance of Directive.
14 15 16 17 |
# File 'lib/coppertone/directive.rb', line 14 def initialize(qualifier, mechanism) @qualifier = qualifier @mechanism = mechanism end |
Instance Attribute Details
#mechanism ⇒ Object (readonly)
Returns the value of attribute mechanism.
9 10 11 |
# File 'lib/coppertone/directive.rb', line 9 def mechanism @mechanism end |
#qualifier ⇒ Object (readonly)
Returns the value of attribute qualifier.
9 10 11 |
# File 'lib/coppertone/directive.rb', line 9 def qualifier @qualifier end |
Class Method Details
.matching_term(text) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/coppertone/directive.rb', line 43 def self.matching_term(text) return nil if text.include?('=') matches = DIRECTIVE_REGEXP.match(text) return nil unless matches qualifier_txt = matches[1] mechanism_type = matches[2].downcase attributes = matches[3] qualifier = Qualifier.find_by_text(qualifier_txt) mechanism = Mechanism.build(mechanism_type, attributes) return nil unless qualifier && mechanism new(qualifier, mechanism) end |
Instance Method Details
#all? ⇒ Boolean
33 34 35 |
# File 'lib/coppertone/directive.rb', line 33 def all? mechanism.is_a?(Coppertone::Mechanism::All) end |
#evaluate(context, options) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/coppertone/directive.rb', line 19 def evaluate(context, ) if mechanism.match?(context, ) Coppertone::Result.from_directive(self) else Result.none end end |
#target_domain ⇒ Object
27 28 29 30 31 |
# File 'lib/coppertone/directive.rb', line 27 def target_domain raise NeedsContextError unless dns_lookup_term? mechanism.target_domain end |
#to_s ⇒ Object
37 38 39 40 |
# File 'lib/coppertone/directive.rb', line 37 def to_s mechanism_s = mechanism.to_s qualifier.default? ? mechanism_s : "#{qualifier}#{mechanism_s}" end |