Class: Coppertone::TermsParser
- Inherits:
-
Object
- Object
- Coppertone::TermsParser
- Defined in:
- lib/coppertone/terms_parser.rb
Overview
Parses a un-prefixed string into terms
Instance Attribute Summary collapse
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Instance Method Summary collapse
-
#initialize(text) ⇒ TermsParser
constructor
A new instance of TermsParser.
- #parse_token(token) ⇒ Object
- #terms ⇒ Object
- #tokens ⇒ Object
Constructor Details
#initialize(text) ⇒ TermsParser
Returns a new instance of TermsParser.
5 6 7 |
# File 'lib/coppertone/terms_parser.rb', line 5 def initialize(text) @text = text end |
Instance Attribute Details
#text ⇒ Object (readonly)
Returns the value of attribute text.
4 5 6 |
# File 'lib/coppertone/terms_parser.rb', line 4 def text @text end |
Instance Method Details
#parse_token(token) ⇒ Object
17 18 19 20 21 |
# File 'lib/coppertone/terms_parser.rb', line 17 def parse_token(token) term = Term.build_from_token(token) raise RecordParsingError unless term term end |
#terms ⇒ Object
9 10 11 |
# File 'lib/coppertone/terms_parser.rb', line 9 def terms tokens.map { |token| parse_token(token) } end |
#tokens ⇒ Object
13 14 15 |
# File 'lib/coppertone/terms_parser.rb', line 13 def tokens text.split(/ /).reject(&:blank?) end |