Class: NameTamer::Text
- Inherits:
-
Object
- Object
- NameTamer::Text
- Defined in:
- lib/name_tamer/text.rb
Instance Method Summary collapse
- #neighbours ⇒ Object
-
#parameterize ⇒ Object
The string as a slug.
-
#segments ⇒ Object
Split the string into segments (e.g. sentences).
-
#slugs ⇒ Object
All the potential slugs from the string e.g.
Instance Method Details
#neighbours ⇒ Object
28 29 30 |
# File 'lib/name_tamer/text.rb', line 28 def neighbours @neighbours ||= NameTamer[string].array.neighbours.map { |a| a.join('-') } end |
#parameterize ⇒ Object
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 |
#segments ⇒ Object
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 |
#slugs ⇒ Object
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 |