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.freeze
- ALLOWED_CHARACTERS =
/\A([\x21-\x7e ]+)\z/.freeze
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.
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
#terms ⇒ Object (readonly)
Returns the value of attribute terms.
15 16 17 |
# File 'lib/coppertone/record_term_parser.rb', line 15 def terms @terms end |
#text ⇒ Object (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
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_segment ⇒ Object
25 26 27 |
# File 'lib/coppertone/record_term_parser.rb', line 25 def terms_segment text[VERSION_STR.length..].strip end |