Class: Rundown::Processors::Phone

Inherits:
Rundown::Processor show all
Defined in:
lib/rundown/processors/phone.rb

Constant Summary

Constants inherited from Rundown::Processor

Rundown::Processor::PUNCTUATION

Instance Attribute Summary collapse

Attributes inherited from Rundown::Processor

#words

Instance Method Summary collapse

Methods inherited from Rundown::Processor

#sentences

Constructor Details

#initialize(words, formatter = Phony) ⇒ Phone

Returns a new instance of Phone.



6
7
8
9
# File 'lib/rundown/processors/phone.rb', line 6

def initialize(words, formatter=Phony)
  @text = words
  @formatter = formatter
end

Instance Attribute Details

#formatterObject

Returns the value of attribute formatter.



4
5
6
# File 'lib/rundown/processors/phone.rb', line 4

def formatter
  @formatter
end

#textObject

Returns the value of attribute text.



4
5
6
# File 'lib/rundown/processors/phone.rb', line 4

def text
  @text
end

Instance Method Details

#format(number) ⇒ Object



11
12
13
# File 'lib/rundown/processors/phone.rb', line 11

def format(number)
  number.start_with?('0') ? number : formatter.formatted(number)
end

#processObject



15
16
17
# File 'lib/rundown/processors/phone.rb', line 15

def process
  remove_punctuation(text).scan(/\d{7,13}/).map {|number| format(number) }
end