class Ppl::Command::Scrape

Attributes

email_scraper[W]

Public Instance Methods

execute(input, output) click to toggle source
# File lib/ppl/command/scrape.rb, line 20
def execute(input, output)
  contacts = scrape_email(input)
  contacts.each do |contact|
    if store_contact?(contact, input)
      @storage.save_contact(contact)
    end
  end
  return true
end
options(parser, options) click to toggle source
# File lib/ppl/command/scrape.rb, line 10
def options(parser, options)
  parser.banner = "usage: ppl scrape [<options>]"
  parser.on("-q", "--quiet", "Add contacts to the address book without prompting") do |i|
    options[:quiet] = i
  end
  parser.on("-s", "--sender", "Scrape the sender's contact details") do |i|
    options[:sender] = i
  end
end

Private Instance Methods

generate_prompt_string(contact) click to toggle source
# File lib/ppl/command/scrape.rb, line 56
def generate_prompt_string(contact)
  sprintf('Add "%s <%s>" to your address book [Y/n]? ',
    contact.name,
    contact.email_addresses.first
  )
end
scrape_email(input) click to toggle source
# File lib/ppl/command/scrape.rb, line 32
def scrape_email(input)
  ARGV.shift
  email = input.stdin.read
  contacts = []
  if input.options[:sender]
    contacts |= scrape_sender(email)
  end
  contacts
end
scrape_sender(email) click to toggle source
# File lib/ppl/command/scrape.rb, line 42
def scrape_sender(email)
  @email_scraper.scrape_contacts(email)
end
store_contact?(contact, input) click to toggle source
# File lib/ppl/command/scrape.rb, line 46
def store_contact?(contact, input)
  if input.options[:quiet]
    true
  else
    input.stdin.reopen("/dev/tty", "r") if input.stdin.eof?
    message = generate_prompt_string(contact)
    Readline.readline(message).downcase != "n"
  end
end