Class: Coppertone::TermsParser

Inherits:
Object
  • Object
show all
Defined in:
lib/coppertone/terms_parser.rb

Overview

Parses a un-prefixed string into terms

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#textObject (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

Raises:



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

#termsObject



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

def terms
  tokens.map { |token| parse_token(token) }
end

#tokensObject



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

def tokens
  text.split(/ /).reject(&:blank?)
end