Class: Coppertone::RecordTermParser
- Inherits:
-
Object
- Object
- Coppertone::RecordTermParser
- 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
-
#terms ⇒ Object
readonly
Returns the value of attribute terms.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(text) ⇒ RecordTermParser
constructor
A new instance of RecordTermParser.
- #terms_segment ⇒ Object
Constructor Details
#initialize(text) ⇒ RecordTermParser
Returns a new instance of RecordTermParser.
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
#terms ⇒ Object (readonly)
Returns the value of attribute terms.
13 14 15 |
# File 'lib/coppertone/record_term_parser.rb', line 13 def terms @terms end |
#text ⇒ Object (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
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_segment ⇒ Object
21 22 23 |
# File 'lib/coppertone/record_term_parser.rb', line 21 def terms_segment text[VERSION_STR.length..-1].strip end |