OICFiscalPrinterLibOCX 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a66706e5b25a4608ce690a5fca5bda4064074b30
4
+ data.tar.gz: 60b950e705a11066c2d2128fa6306b8773b2caed
5
+ SHA512:
6
+ metadata.gz: 7e2f8144e62a1b558f59fcd283a391eac33a65e5068d3e7c691ece7c9fe3f618a2fcfdd21380ccfdbc8d6085d6f666924d656cb4616eb4eb5c8ffc1b2908bb4f
7
+ data.tar.gz: 2c642083bfcd54a623c369882eb50cd67747173d7c444828e9b3900bf2f88fdad01befae6e39a39984e561fb6222cb8ed202962b09d529a5150e696075a4ad4b
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014 Maciej Stanczyk
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = OICFiscalPrinterLibOCX
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to OICFiscalPrinterLibOCX
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
+ * Fork the project.
10
+ * Start a feature/bugfix branch.
11
+ * Commit and push until you are happy with your contribution.
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2014 Maciej Stanczyk. See LICENSE.txt for
18
+ further details.
19
+
@@ -0,0 +1,70 @@
1
+ require 'win32ole'
2
+ require_relative 'connection_factory.rb'
3
+ require_relative 'errors.rb'
4
+
5
+ class OICFiscalPrinterLib
6
+ attr_accessor :connection
7
+
8
+ def initialize(args)
9
+ @connection = WIN32OLE.new('OICFiscalPrinterLib.OICFiscalPrinter')
10
+
11
+ @connection.PortConfigString = ConnectionFactory.new(args).port_config_string
12
+
13
+ @connection.PrinterDriver = args[:printerdriver] || default_printerdriver
14
+
15
+ @connection.LogTransmission = args.fetch(:logtransmission, default_logtransmission)
16
+ @connection.LogFolderName = args[:logfoldername] || default_logfoldername
17
+
18
+ initialize_extra(args)
19
+ end
20
+
21
+ def initialize_extra(args)
22
+ end
23
+
24
+
25
+ def method_missing(method_name, *args)
26
+ is_property = false
27
+ if method_name.match(/=$/)
28
+ method_name = method_name.to_s.gsub(/=$/,'')
29
+ is_property = true
30
+ else
31
+ method_name = method_name.to_s
32
+ end
33
+
34
+ if respond_to?(method_name)
35
+ if is_property
36
+ connection.setproperty(method_name, *args)
37
+ else
38
+ connection.send(method_name, *args) #if ready?
39
+ end
40
+ else
41
+ raise NoMethodError, "undefined method `#{method_name}' for OICFiscalPrinterLib interface"
42
+ end
43
+ end
44
+
45
+ def respond_to?(method_name)
46
+ @connection.ole_respond_to?(method_name)
47
+ end
48
+
49
+ protected
50
+ def default_logtransmission
51
+ false
52
+ end
53
+
54
+ def default_logfoldername
55
+ 'log'
56
+ end
57
+
58
+ def default_printerdriver
59
+ 'HD E PL 1.0'
60
+ end
61
+
62
+ def ready?
63
+ result = false
64
+ result = connection.ReadDLEStatus(nil, nil, nil)
65
+ unless result
66
+ raise ConnectionError, "#{connection.lasterror}: #{connection.lasterrormessage}"
67
+ end
68
+ result
69
+ end
70
+ end
@@ -0,0 +1,52 @@
1
+ class ComConnection
2
+ attr_reader :portname, :databits, :speed, :parity, :stopbits, :flowcontrol, :readtimeout, :writetimeout, :usereadbuffer
3
+
4
+ def initialize(args)
5
+ @portname = args[:portname]
6
+ @databits = args[:databits] || default_databits
7
+ @speed = args[:speed] || default_speed
8
+ @parity = args[:parity] || default_parity
9
+ @stopbits = args[:stopbits] || default_stopbits
10
+ @flowcontrol = args[:flowcontrol] || default_flowcontrol
11
+ @readtimeout = args[:readtimeout] || default_readtimeout
12
+ @writetimeout = args[:writetimeout] || default_writetimeout
13
+ @usereadbuffer = args[:usereadbuffer] || default_usereadbuffer
14
+ end
15
+
16
+ def port_config_string
17
+ "PortName=#{portname};DataBits=#{databits};Speed=#{speed};Parity=#{parity};StopBits=#{stopbits};FlowControl=#{flowcontrol};ReadTimeout=#{readtimeout};WriteTimeout=#{writetimeout};UseReadBuffer=#{usereadbuffer}"
18
+ end
19
+
20
+ private
21
+ def default_databits
22
+ 8
23
+ end
24
+
25
+ def default_speed
26
+ 9600
27
+ end
28
+
29
+ def default_parity
30
+ 'N'
31
+ end
32
+
33
+ def default_stopbits
34
+ 1
35
+ end
36
+
37
+ def default_flowcontrol
38
+ 'X'
39
+ end
40
+
41
+ def default_readtimeout
42
+ 40000
43
+ end
44
+
45
+ def default_writetimeout
46
+ 50
47
+ end
48
+
49
+ def default_usereadbuffer
50
+ 0
51
+ end
52
+ end
@@ -0,0 +1,30 @@
1
+ require_relative 'ethernet_connection.rb'
2
+ require_relative 'com_connection.rb'
3
+
4
+ class ConnectionFactory
5
+ attr_reader :connection
6
+
7
+ def initialize(args)
8
+ hash_with_indifferent_access(args)
9
+ if args[:host].nil?
10
+ @connection = ComConnection.new(args)
11
+ else
12
+ @connection = EthernetConnection.new(args)
13
+ end
14
+ end
15
+
16
+ def port_config_string
17
+ @connection.port_config_string
18
+ end
19
+
20
+ private
21
+ def hash_with_indifferent_access(args)
22
+ args.default_proc = proc do |h, k|
23
+ case k
24
+ when String then sym = k.to_sym; h[sym] if h.key?(sym)
25
+ when Symbol then str = k.to_s; h[str] if h.key?(str)
26
+ end
27
+ end
28
+ end
29
+
30
+ end
data/lib/errors.rb ADDED
@@ -0,0 +1,5 @@
1
+ class OICFiscalPrinterLib
2
+ class Error < StandardError; end
3
+ class ConnectionError < Error; end
4
+ class ArgumentError < Error; end
5
+ end
@@ -0,0 +1,27 @@
1
+ class EthernetConnection
2
+ attr_reader :portname, :host, :port, :connectiontimeout, :timeout
3
+ def initialize(args)
4
+ @portname = 'TCP/IP'
5
+ @host = args[:host]
6
+ @port = args[:port] || default_port
7
+ @connectiontimeout = args[:connectiontimeout] || default_connectiontimeout
8
+ @timeout = args[:timeout] || default_timeout
9
+ end
10
+
11
+ def port_config_string
12
+ "PortName=#{portname};Host=#{host};Port=#{port};ConnectionTimeout=#{connectiontimeout};Timeout=timeout"
13
+ end
14
+
15
+ private
16
+ def default_port
17
+ 6001
18
+ end
19
+
20
+ def default_connectiontimeout
21
+ 10000
22
+ end
23
+
24
+ def default_timeout
25
+ 30000
26
+ end
27
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: OICFiscalPrinterLibOCX
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Maciej Stanczyk
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: shoulda
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rdoc
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '3.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '3.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: jeweler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 2.0.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 2.0.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: OICFiscalPrinterLib is activex library for Novitus fiscal devices.
84
+ email: maciej.stanczyk@mastasoft.pl
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files:
88
+ - LICENSE.txt
89
+ - README.rdoc
90
+ files:
91
+ - LICENSE.txt
92
+ - README.rdoc
93
+ - lib/OICFiscalPrinterLibOCX.rb
94
+ - lib/com_connection.rb
95
+ - lib/connection_factory.rb
96
+ - lib/errors.rb
97
+ - lib/ethernet_connection.rb
98
+ homepage: http://github.com/macler/OICFiscalPrinterLibOCX
99
+ licenses:
100
+ - MIT
101
+ metadata: {}
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project:
118
+ rubygems_version: 2.4.4
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: OICFiscalPrinterLib is activex library for Novitus fiscal devices.
122
+ test_files: []