Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/activefacts/support.rb

Defined Under Namespace

Classes: Words

Instance Method Summary collapse

Instance Method Details

#wordsObject



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/activefacts/support.rb', line 132

def words
  Words.new(
    self.
    split(
      %r{     # Split and discard any group of non-alphanumeric characters:
        (?:[^[:alnum:]]+)
        |     # Split between an uppercase and a preceding lowercase or digit:
        (?<=[[:lower:][:digit:]])(?=[[:upper:]])
        |     # Split between any alphanumeric and a following upper-lower pair:
        (?<=[[:alnum:]])(?=[[:upper:]][[:lower:]])
      }x
    ).
    reject{|w| w == '' }.
    # Any word that starts with a digit gets an _
    map{|w| w =~ /^[^_[:alpha:]]/ ? '_'+w : w}
  )
end