Sha256: cee7d54762704bb07a672622f76c45cbe274984de41fe0fe6e3db81979a96a5e
Contents?: true
Size: 1.41 KB
Versions: 2
Compression:
Stored size: 1.41 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{7,}$ # followed by at least 8 digits }x attr_reader :logger def initialize(job, opts = {}) @job = job @opts = opts @logger = opts[:logger] end # Actually fax the letter. def run system(command) unless @opts[:noop] logger.debug :message => 'Letter faxed', :phone => validated_phone, :letter => @job.letter, :job => @job 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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
wicoris-postman-0.11.3 | lib/wicoris/postman/fax_machine.rb |
wicoris-postman-0.11.2 | lib/wicoris/postman/fax_machine.rb |