class NameTamer::Text
Attributes
args[R]
string[R]
Public Class Methods
new(string, args = {})
click to toggle source
# File lib/name_tamer/text.rb, line 36 def initialize(string, args = {}) @string = string @args = args end
Public Instance Methods
neighbours()
click to toggle source
# File lib/name_tamer/text.rb, line 28 def neighbours @neighbours ||= NameTamer[string].array.neighbours.map { |a| a.join('-') } end
parameterize()
click to toggle source
The string as a slug
# 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()
click to toggle source
Split the string into segments (e.g. sentences)
# File lib/name_tamer/text.rb, line 10 def segments string.split(%r{(?:[\.\?,:;!]|[[:space:]][/-])[[:space:]]}) end
slugs()
click to toggle source
All the potential slugs from the string e.g. ‘lorem ipsum dolor’ -> [‘lorem’, ‘ipsum’ ,‘dolor’, ‘lorem-ipsum’, ‘ipsum-dolor’, ‘lorem-ipsum-dolor’]
# File lib/name_tamer/text.rb, line 5 def slugs @slugs ||= segments.flat_map { |s| self.class.new(s).neighbours }.uniq end
Private Instance Methods
filter()
click to toggle source
# File lib/name_tamer/text.rb, line 49 def filter @filter ||= args[:filter] || (rfc3987 ? FILTER_RFC3987 : FILTER_COMPAT) end
rfc3987()
click to toggle source
# File lib/name_tamer/text.rb, line 45 def rfc3987 @rfc3987 ||= args[:rfc3987] || false end
separator()
click to toggle source
# File lib/name_tamer/text.rb, line 41 def separator @seperator ||= args[:sep] || SLUG_DELIMITER end