class Wco::Leadset

def self.from_email email

for anti-spam
def self.from_email email
  _domain = email.split('@')[1]
  words = _domain.split('.')
  if %w| com net gov org |.include?( words[-2] )
    words = words[-3, 3]
  else
    words = words[-2, 2]
  end
  _domain = words.join('.')
  find_or_create_by( company_url: _domain )
end

def self.list

def self.list
  [[nil,nil]] + all.map { |ttt| [ ttt.company_url, ttt.id ] }
end

def convs; conversations; end

def convs; conversations; end

def customer_id

def customer_id
  if self[:customer_id].blank?
    return nil if !email.present?
    existing = Stripe::Customer.search({ query: "email: '#{email}'" })
    if existing.data.present?
      update_attributes( customer_id: existing.data[0][:id] )
    else
      customer = Stripe::Customer.create({ email: email })
      update_attributes( customer_id: customer[:id] )
    end
  end
  self[:customer_id]
end

def domain; company_url; end # for anti-spam

for anti-spam
def domain; company_url; end # for anti-spam

def next_serverhost

, inverse_of: :leadset
def next_serverhost
  serverhosts.first
end

def normalize_company_url

def normalize_company_url
  company_url.downcase!
end

def to_s

def to_s
  company_url
end