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



6
7
8
# File 'lib/coppertone/terms_parser.rb', line 6

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:



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

#termsObject



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

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

#tokensObject



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

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