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
ALLOWED_CHARACTERS =
/\A([\x21-\x7e ]+)\z/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ RecordTermParser

Returns a new instance of RecordTermParser.

Raises:



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

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.



13
14
15
# File 'lib/coppertone/record_term_parser.rb', line 13

def terms
  @terms
end

#textObject (readonly)

Returns the value of attribute text.



13
14
15
# File 'lib/coppertone/record_term_parser.rb', line 13

def text
  @text
end

Class Method Details

.record?(text) ⇒ Boolean

Returns:

  • (Boolean)


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

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

Instance Method Details

#terms_segmentObject



21
22
23
# File 'lib/coppertone/record_term_parser.rb', line 21

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