Class: Sep::Separator

Inherits:
Object
  • Object
show all
Defined in:
lib/sep/separator.rb

Constant Summary collapse

ANALYSIS =
/([[:punct:]\s]*)(\w+)([[:punct:]]*)(\s*)/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ Separator

text - String text to separate



8
9
10
11
12
# File 'lib/sep/separator.rb', line 8

def initialize(text)
  @text = text

  analyze
end

Instance Attribute Details

#textObject (readonly)

Returns the value of attribute text.



3
4
5
# File 'lib/sep/separator.rb', line 3

def text
  @text
end

#words_dataObject (readonly)

Returns the value of attribute words_data.



3
4
5
# File 'lib/sep/separator.rb', line 3

def words_data
  @words_data
end

Instance Method Details

#leading_spaceObject



14
15
16
# File 'lib/sep/separator.rb', line 14

def leading_space
  text.match(/(\s*)/).captures[0]
end

#spaceObject



18
19
20
# File 'lib/sep/separator.rb', line 18

def space
  [leading_space] + words_data.map {|wd| wd[:space_post] }
end

#wordsObject



22
23
24
# File 'lib/sep/separator.rb', line 22

def words
  words_data.map {|wd| wd[:word] }
end