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
6 7 8 |
# File 'lib/coppertone/terms_parser.rb', line 6 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
18 19 20 21 22 23 |
# File 'lib/coppertone/terms_parser.rb', line 18 def parse_token(token) term = Term.build_from_token(token) raise RecordParsingError unless term term end |
#terms ⇒ Object
10 11 12 |
# File 'lib/coppertone/terms_parser.rb', line 10 def terms tokens.map { |token| parse_token(token) } end |
#tokens ⇒ Object
14 15 16 |
# File 'lib/coppertone/terms_parser.rb', line 14 def tokens text.split(/ /).reject(&:blank?) end |