Class: Coppertone::Qualifier

Inherits:
Object
  • Object
show all
Defined in:
lib/coppertone/qualifier.rb

Overview

Instances of this class represent qualifiers, as defined by the SPF specification (see section 4.6.1).

There are only 4 qualifiers permitted by the specification, so this class does not allow the creation of new instances. These fixed instances should be accessed through either the class level constants or the qualifiers class method.

Constant Summary collapse

DEFAULT_QUALIFIER_TEXT =
'+'.freeze
PASS =
new(DEFAULT_QUALIFIER_TEXT, Result::PASS)
FAIL =
new('-'.freeze, Result::FAIL)
SOFTFAIL =
new('~'.freeze, Result::SOFTFAIL)
NEUTRAL =
new('?'.freeze, Result::NEUTRAL)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text, result_code) ⇒ Qualifier

Returns a new instance of Qualifier.



25
26
27
28
# File 'lib/coppertone/qualifier.rb', line 25

def initialize(text, result_code)
  @text = text
  @result_code = result_code
end

Instance Attribute Details

#result_codeObject (readonly)

Returns the value of attribute result_code.



24
25
26
# File 'lib/coppertone/qualifier.rb', line 24

def result_code
  @result_code
end

#textObject (readonly)

Returns the value of attribute text.



24
25
26
# File 'lib/coppertone/qualifier.rb', line 24

def text
  @text
end

Class Method Details

.default_qualifierObject



20
21
22
# File 'lib/coppertone/qualifier.rb', line 20

def self.default_qualifier
  find_by_text(nil)
end

.find_by_text(text) ⇒ Object



15
16
17
18
# File 'lib/coppertone/qualifier.rb', line 15

def self.find_by_text(text)
  text = DEFAULT_QUALIFIER_TEXT if text.blank?
  @qualifier_hash[text]
end

.qualifiersObject



45
46
47
# File 'lib/coppertone/qualifier.rb', line 45

def self.qualifiers
  [PASS, FAIL, SOFTFAIL, NEUTRAL]
end

Instance Method Details

#default?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/coppertone/qualifier.rb', line 30

def default?
  text == DEFAULT_QUALIFIER_TEXT
end

#to_sObject



34
35
36
# File 'lib/coppertone/qualifier.rb', line 34

def to_s
  text
end