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
29 30 31 |
# File 'lib/name_tamer/text.rb', line 29 def neighbours @neighbours ||= contiguous_slices(NameTamer[string].array).map { |words| words.join('-') } end |
#parameterize ⇒ Object
The string as a slug
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/name_tamer/text.rb', line 17 def parameterize @parameterize ||= begin slug = Strings.whitespace_to(string, separator) slug = Strings.invalid_chars_to(slug, separator) slug = Strings.strip_unwanted(slug, filter) slug = Strings.fix_separators(slug, separator) slug = Strings.approximate_latin_chars(slug) (Strings.presence(slug) || '_').downcase end end |
#segments ⇒ Object
Split the string into segments (e.g. sentences)
12 13 14 |
# File 'lib/name_tamer/text.rb', line 12 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']
7 8 9 |
# File 'lib/name_tamer/text.rb', line 7 def slugs @slugs ||= segments.flat_map { |s| self.class.new(s).neighbours }.uniq end |