Class: NameTamer::Text

Inherits:
Object
  • Object
show all
Defined in:
lib/name_tamer/text.rb

Instance Method Summary collapse

Instance Method Details

#neighboursObject



28
29
30
# File 'lib/name_tamer/text.rb', line 28

def neighbours
  @neighbours ||= NameTamer[string].array.neighbours.map { |a| a.join('-') }
end

#parameterizeObject

The string as a slug



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/name_tamer/text.rb', line 15

def parameterize
  @parameterize ||= (
    string
    .dup
    .whitespace_to!(separator)
    .invalid_chars_to!(separator)
    .strip_unwanted!(filter)
    .fix_separators!(separator)
    .approximate_latin_chars!
    .presence || '_'
  ).downcase
end

#segmentsObject

Split the string into segments (e.g. sentences)



10
11
12
# File 'lib/name_tamer/text.rb', line 10

def segments
  string.split(%r{(?:[\.\?,:;!]|[[:space:]][/-])[[:space:]]})
end

#slugsObject

All the potential slugs from the string e.g. ‘lorem ipsum dolor’ -> [‘lorem’, ‘ipsum’ ,‘dolor’, ‘lorem-ipsum’, ‘ipsum-dolor’, ‘lorem-ipsum-dolor’]



5
6
7
# File 'lib/name_tamer/text.rb', line 5

def slugs
  @slugs ||= segments.flat_map { |s| self.class.new(s).neighbours }.uniq
end