Sha256: a5d55059ca88e753df433bcda025471e90a5cdc32da4a05c86353a58b2f17b79

Contents?: true

Size: 1.75 KB

Versions: 1

Compression:

Stored size: 1.75 KB

Contents

require 'yaml'
require 'erb'


module Sapos
  module Print
    class Configuration
    
      attr_accessor :printer, :adapter, :interface, :q, :key, :emv_path, :emv_terminal, :user_id, :verbose, :duplicate_control, :cache, :printers, :verbose
    
      def self.write(args = {})
        config_file = "#{Sapos::Print.app_directory}/config.yml"
        File.write(config_file, args.to_yaml)
      end
    
      def initialize
        config_file = "#{Sapos::Print.app_directory}/config.yml"
        if File.exist?(config_file)
          template = ERB.new(File.read(config_file))
          result = YAML.load(template.result(binding))
          @printer = result[:printer]
          @printers = result[:printers] || []
          @adapter = result[:adapter]
          @interface = result[:interface]
          @q = result[:q]
          @key = result[:key]
          @emv_path = result[:emv_path]
          @emv_terminal = result[:emv_terminal]
          @user_id = result[:user_id]
          @duplicate_control = result[:duplicate_control]
          @verbose = result[:verbose]
          @cache = []
        else
          raise Sapos::Print::Error, "Configuration is missing. Make sure to create this file: #{config_file}"
        end
      end
    
      def server?
        @mode.eql?("server")
      end
    
      def queue?
        @mode.eql?("queue")
      end
    
      def verify?
        @verify == true
      end
      
      def duplicate_control?
        @duplicate_control.to_s.downcase.eql?("si")
      end
    
      def to_h
        {printer: @printer, adapter: @adapter, interface: @interface, q: @q, key: @key, emv_path: @emv_path, emv_terminal: @emv_terminal, user_id: @user_id, duplicate_control: @duplicate_control, printers: @printers }
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sapos-print-1.1.1 lib/sapos/print/configuration.rb