Method: Treat::Entities::Entity::Buildable#token_from_string

Defined in:
lib/treat/entities/entity/buildable.rb

#token_from_string(string) ⇒ Object

Build the right type of token corresponding to a string.



347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
# File 'lib/treat/entities/entity/buildable.rb', line 347

def token_from_string(string)

  check_encoding(string)
  if Enclitics.include?(string.downcase)
    Treat::Entities::Enclitic.new(string)
  elsif string =~ WordRegexp &&
    string.count(' ') == 0 &&
    string != '-'
    Treat::Entities::Word.new(string)
  elsif string =~ NumberRegexp
    from_numeric(string)
  elsif string =~ PunctRegexp
    Treat::Entities::Punctuation.new(string)
  elsif string.count('.') > 0 &&
    string =~ UriRegexp
    Treat::Entities::Url.new(string)
  elsif string.count('@') > 0 &&
    string =~ EmailRegexp
    Treat::Entities::Email.new(string)
  else
    Treat::Entities::Symbol.new(string)
  end
end