class Wicoris::Postman::FaxMachine

Constants

DIALOUT_PREFIX
VALID_PHONE_NUMBER

Attributes

logger[R]

Public Class Methods

new(job, opts = {}) click to toggle source
# File lib/wicoris/postman/fax_machine.rb, line 13
def initialize(job, opts = {})
  @job = job
  @opts = opts
  @logger = opts[:logger]
end

Public Instance Methods

run() click to toggle source

Actually fax the letter.

# File lib/wicoris/postman/fax_machine.rb, line 20
def run
  Mixlib::ShellOut.new(command).run_command unless @opts[:noop]
  logger.debug :message => 'Letter faxed',
               :phone => validated_phone,
               :letter => @job.letter,
               :job => @job
end
validated_phone() click to toggle source

@returns [String] Validated phone number.

# File lib/wicoris/postman/fax_machine.rb, line 29
def validated_phone
  raise ArgumentError, 'Missing phone number' unless @job.phone
  phone = @job.phone.gsub(/(\s|-)+/, '')
  if phone =~ VALID_PHONE_NUMBER
    DIALOUT_PREFIX + phone
  else
    raise ArgumentError, "Invalid phone number: #{phone}"
  end
end

Private Instance Methods

command() click to toggle source

Return the command-line for sending the fax, i.e.:

lp -d Fax -o phone=042 "/tmp/foo.pdf"

@returns [String] command-line

# File lib/wicoris/postman/fax_machine.rb, line 46
def command
  cmd = %w(lp -d Fax) # TODO: Replace hard-coded fax printer-name 'Fax'!
  cmd << "-o phone=#{validated_phone}"
  cmd << "'#{@job.letter}'"
  cmd.join(' ')
end