Class: Coppertone::RecordTermParser

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

Overview

Parses a record into terms

Constant Summary collapse

VERSION_STR =
'v=spf1'.freeze
RECORD_REGEXP =
/\A#{VERSION_STR}(\s|\z)/i.freeze
ALLOWED_CHARACTERS =
/\A([\x21-\x7e ]+)\z/.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ RecordTermParser

Returns a new instance of RecordTermParser.

Raises:



17
18
19
20
21
22
23
# File 'lib/coppertone/record_term_parser.rb', line 17

def initialize(text)
  raise RecordParsingError unless self.class.record?(text)
  raise RecordParsingError unless ALLOWED_CHARACTERS.match?(text)

  @text = text
  @terms = Coppertone::TermsParser.new(terms_segment).terms
end

Instance Attribute Details

#termsObject (readonly)

Returns the value of attribute terms.



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

def terms
  @terms
end

#textObject (readonly)

Returns the value of attribute text.



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

def text
  @text
end

Class Method Details

.record?(text) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
11
12
13
# File 'lib/coppertone/record_term_parser.rb', line 8

def self.record?(text)
  return false if text.blank?
  return true if RECORD_REGEXP.match?(text.strip)

  false
end

Instance Method Details

#terms_segmentObject



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

def terms_segment
  text[VERSION_STR.length..].strip
end