Sha256: fde11d05cc32c3b7245a2cad79e686acd5ab6abf4c357d115be8afde44ec3dd2
Contents?: true
Size: 1.35 KB
Versions: 1
Compression:
Stored size: 1.35 KB
Contents
module Wicoris module Postman class FaxMachine DIALOUT_PREFIX = '0' VALID_PHONE_NUMBER = %r{ ^0 # starts with a zero [1-9]{1} # but not with a second zero \d{8,}$ # followed by at least 8 digits }x def initialize(job, opts = {}) @job = job @opts = opts @logger = opts[:logger] end # Actually fax the letter. def run system(command) unless @opts[:noop] if @logger msg = @job.to_hash msg[:message] = 'Letter delivered :-)' @logger.info(msg) end end # @returns [String] Validated phone number. 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 # Return the command-line for sending the fax, i.e.: # # lp -d Fax -o phone=042 "/tmp/foo.pdf" # # @returns [String] command-line 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 end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
wicoris-postman-0.10.0 | lib/wicoris/postman/fax_machine.rb |