da_funk 0.4.12 → 0.4.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1bca50eede080553cf6fa25ad14e52d2202186ec
4
- data.tar.gz: 45727a4dc48d2bb22cdbedbd98c26f0d8c7c83df
3
+ metadata.gz: c71a022894a2992a96f807725594df7a54d9a27d
4
+ data.tar.gz: ae01716d14310f7cfb1a6d9621cfd1bb3bc80766
5
5
  SHA512:
6
- metadata.gz: d7d29e9d7cf081450c088c906e0b29c8df40f337508ae80c165a7b4d8e0c7bbe48e5302fce1fa5a262c83657a29ac2c240c7be93d94cabd6edff4103e94a76e8
7
- data.tar.gz: 34f0af6e7974b2c42ff063ee026701d808481048d0e60d0ecb0ccd1ec5464071b4a1e5c4b2bf1984ce7c7aea044bc21e9cf54cac7224b5b851a68647e6d27f00
6
+ metadata.gz: 29d9509398e039740dbbcda5ab21276c192e465fac94f4eb725166d09b9759b6f5a46947e29316e7821ddaea8373f39761125ffab51f993a2b65f8e3a5f5358e
7
+ data.tar.gz: 3fe51480128815ddfedd6b7442bda0c81a2c1aaae3a863e41829f8a859d181ba54ec450d510b0af5313b70ce4300c2bd161e2bd1bb6a377edb40447d16901cb7
data/Gemfile.lock CHANGED
@@ -7,7 +7,7 @@ GIT
7
7
  PATH
8
8
  remote: .
9
9
  specs:
10
- da_funk (0.4.12)
10
+ da_funk (0.4.15)
11
11
  bundler (~> 1.7)
12
12
  cloudwalk_handshake (~> 0.4)
13
13
  rake (~> 10.4)
@@ -16,7 +16,7 @@ PATH
16
16
  GEM
17
17
  remote: https://rubygems.org/
18
18
  specs:
19
- cloudwalk_handshake (0.4.1)
19
+ cloudwalk_handshake (0.4.5)
20
20
  rake (10.4.2)
21
21
  yard (0.8.7.6)
22
22
 
data/RELEASE_NOTES.md CHANGED
@@ -1,5 +1,35 @@
1
1
  # DaFunk
2
2
 
3
+ ### 0.4.15 - 2015-11-24 - Screen limitation abstraction
4
+ - Implement class Screen to replace STDOUT and perform column and line display abstraction on place that doesn’t support screen display by STDOUT.
5
+
6
+ ### 0.4.14 - 2015-11-23 - Improve IO functions
7
+ - Update cloudwalk_handshake to version 0.4.5.
8
+ - Apply relative path on compilation and tests paths to make it work properly on windows.
9
+ - Move from Print to Printer.
10
+ - Implement Device::Print.print_big.
11
+ - Support to display in line at Device::IO.get_format.
12
+ - On Helper.menu support Device::IO.timeout if timeout isn’t send.
13
+ - Refactoring the documentation of Helper.menu.
14
+ - Refactoring Device::IO.get_format: Add support masquerade values; Improve the input letters and numbers; Add input alpha.
15
+ - Add the compilation of lib/ext/string.rb on Rakefile.
16
+ - Implement ISO8583 fields Unknown, XN(BCD), LLLVAR_Z and Z (LL Track2).
17
+ - Add iso8583_recv_tries setting.
18
+ - Add uclreceivetimeout to Setting.
19
+ - Add ISO8583::FileParser to parse bitmap.dat file.
20
+
21
+
22
+ ### 0.4.13 - 2015-10-30 - Implement get_string byt getc
23
+ - Implement Debug Flag.
24
+ - Fix Device::IO.change_next to return the first option and restart the loop.
25
+ - Refactor System.restart/reboot
26
+ - Implement timeout on Device::IO.
27
+ - Send nil to getc when show notification message to be blocking.
28
+ - Invert the check of string size on get_string.
29
+ - Use default timeout to menu getc.
30
+ - Call IO::ENTER adding Device:: scope on helpers.
31
+ - Change Device::IO.get_string to work only by getc formatting letters and secret. - Implement DeviceIOTest class.
32
+
3
33
  ### 0.4.12 - 2015-09-02 - helper on ISO8583 load
4
34
  - Bug fix helper load on iso8583.
5
35
 
data/Rakefile CHANGED
@@ -13,6 +13,7 @@ FILES = FileList[
13
13
  "lib/da_funk/helper.rb",
14
14
  "lib/da_funk.rb",
15
15
  "lib/da_funk/test.rb",
16
+ "lib/da_funk/screen.rb",
16
17
  "lib/device.rb",
17
18
  "lib/device/audio.rb",
18
19
  "lib/device/crypto.rb",
@@ -21,7 +22,7 @@ FILES = FileList[
21
22
  "lib/device/io.rb",
22
23
  "lib/device/network.rb",
23
24
  "lib/device/params_dat.rb",
24
- "lib/device/print.rb",
25
+ "lib/device/printer.rb",
25
26
  "lib/device/runtime.rb",
26
27
  "lib/device/setting.rb",
27
28
  "lib/device/support.rb",
@@ -49,7 +50,8 @@ FILES = FileList[
49
50
  "lib/device/application.rb",
50
51
  "lib/zip.rb",
51
52
  "lib/device/magnetic.rb",
52
- "lib/ext/kernel.rb"
53
+ "lib/ext/kernel.rb",
54
+ "lib/ext/string.rb"
53
55
  ]
54
56
 
55
57
  DaFunk::RakeTask.new do |t|
data/lib/da_funk.rb CHANGED
@@ -4,13 +4,14 @@ unless Object.const_defined?(:MTest)
4
4
  require file_path + "/da_funk/iso8583.rb"
5
5
  require file_path + "/da_funk/rake_task.rb"
6
6
  require file_path + "/da_funk/test.rb"
7
+ require file_path + "/da_funk/screen.rb"
7
8
  require file_path + "/device/support.rb"
8
9
  require file_path + "/device/helper.rb"
9
10
  require file_path + "/device/crypto.rb"
10
11
  require file_path + "/device/display.rb"
11
12
  require file_path + "/device/io.rb"
12
13
  require file_path + "/device/network.rb"
13
- require file_path + "/device/print.rb"
14
+ require file_path + "/device/printer.rb"
14
15
  require file_path + "/device/setting.rb"
15
16
  require file_path + "/device/system.rb"
16
17
  require file_path + "/device/version.rb"
@@ -28,7 +29,6 @@ unless Object.const_defined?(:MTest)
28
29
  require file_path + "/device/transaction/download.rb"
29
30
  require file_path + "/device/transaction/emv.rb"
30
31
  require file_path + "/device/transaction/iso.rb"
31
- require file_path + "/../utils/command_line_platform.rb"
32
32
  end
33
33
 
34
34
  module DaFunk
@@ -62,18 +62,39 @@ module DaFunk
62
62
  value
63
63
  end
64
64
 
65
+
66
+ # Create a form menu.
67
+ #
68
+ # @param title [String] Text to display on line 0. If nil title won't be
69
+ # displayed and Display.clear won't be called on before the option show.
70
+ # @param selection [Hash] Hash (display text => value that will return)
71
+ # containing the list options.
72
+ # @param options [Hash] Hash containing options to change the menu behaviour.
73
+ #
65
74
  # @example
66
- # {
67
- # :default => {:detail => 10}, # default value to return if enter
68
- # :number => true, # Add number to label or not
69
- # "option X" => {:detail => 10},
70
- # "option Y" => {:detail => 11}
75
+ # options = {
76
+ # # default value to return if enter, you can work with complex data.
77
+ # :default => 10,
78
+ # # Add number to label or not
79
+ # :number => true,
80
+ # # Input Timeout in miliseconds
81
+ # :timeout => 30_000
82
+ # }
83
+ #
84
+ # selection = {
85
+ # "option X" => 10,
86
+ # "option Y" => 11
71
87
  # }
88
+ #
89
+ # menu("Option menu", selection, options)
90
+ #
72
91
  def menu(title, selection, options = {})
73
92
  options[:number] = true if options[:number].nil?
74
93
 
75
- Device::Display.clear
76
- print_title(title, options[:default])
94
+ if title
95
+ Device::Display.clear
96
+ print_title(title, options[:default])
97
+ end
77
98
  values = Hash.new
78
99
  selection.each_with_index do |value,i|
79
100
  values[i.to_i] = value[1]
@@ -84,9 +105,9 @@ module DaFunk
84
105
  end
85
106
  end
86
107
 
87
- key = getc
108
+ key = getc(options[:timeout] || Device::IO.timeout)
88
109
 
89
- return options[:default] if key == IO::ENTER || key == IO::CANCEL
110
+ return options[:default] if key == Device::IO::ENTER || key == Device::IO::CANCEL
90
111
  [values[key.to_i - 1]].flatten.first
91
112
  end
92
113
 
@@ -145,7 +166,7 @@ module DaFunk
145
166
  private
146
167
  def form_default(options = {})
147
168
  options[:default] ||= ""
148
- options[:mode] ||= Device::IO::IO_INPUT_LETTERS
169
+ options[:mode] ||= Device::IO::IO_INPUT_ALPHA
149
170
  options[:min] ||= 0
150
171
  options[:max] ||= 20
151
172
  options
@@ -9,17 +9,19 @@ module DaFunk
9
9
  class RakeTask < ::Rake::TaskLib
10
10
  include ::Rake::DSL if defined?(::Rake::DSL)
11
11
 
12
- attr_accessor :name, :libs, :tests, :tests_unit, :tests_integration, :root_path, :main_out, :test_out, :resources, :mrbc, :mruby, :out_path, :resources_out
12
+ attr_accessor :name, :libs, :tests, :tests_unit, :tests_integration, :root_path, :main_out,
13
+ :test_out, :resources, :mrbc, :mruby, :out_path, :resources_out, :debug
13
14
 
14
15
  def initialize
15
16
  yield self if block_given?
16
17
 
18
+ @debug ||= true
17
19
  @libs ||= FileList['lib/**/*.rb']
18
20
  @tests ||= FileList['test/**/*test.rb']
19
21
  @tests_integration ||= FileList['test/integration/**/*test.rb']
20
22
  @tests_unit ||= FileList['test/unit/**/*test.rb']
21
- @root_path ||= File.expand_path("./")
22
- @name ||= File.basename(root_path)
23
+ @root_path ||= "./"
24
+ @name ||= File.basename(File.expand_path(@root_path))
23
25
  @out_path ||= File.join(root_path, "out", @name)
24
26
  @main_out ||= File.join(out_path, "main.mrb")
25
27
  @test_out ||= File.join(out_path, "test.mrb")
@@ -31,6 +33,14 @@ module DaFunk
31
33
  define
32
34
  end
33
35
 
36
+ def debug_flag
37
+ if @debug
38
+ "-g"
39
+ else
40
+ ""
41
+ end
42
+ end
43
+
34
44
  def get_mrbc_bin(from_user)
35
45
  if (! system("type mrbc > /dev/null 2>&1 ")) && from_user
36
46
  from_user
@@ -61,11 +71,12 @@ module DaFunk
61
71
  end
62
72
 
63
73
  def execute_tests(files)
74
+ # Debug is always on during tests(-g)
64
75
  all_files = FileList["test/test_helper.rb"] + libs + files + [File.join(File.dirname(__FILE__), "..", "..", "utils", "command_line_platform.rb")] + [File.join(File.dirname(__FILE__), "..", "..", "utils", "test_run.rb")]
65
76
  if sh("#{mrbc} -g -o #{test_out} #{all_files.uniq}")
66
77
  puts "cd #{File.dirname(out_path)}"
67
78
  FileUtils.cd File.dirname(out_path)
68
- sh("#{mruby} #{File.join(out_path, "test.mrb")}")
79
+ sh("#{mruby} #{File.join(name, "test.mrb")}")
69
80
  end
70
81
  end
71
82
 
@@ -98,7 +109,7 @@ module DaFunk
98
109
 
99
110
  desc "Compile app to mrb and process resources"
100
111
  task :build => :resources do
101
- sh "#{mrbc} -g -o #{main_out} #{libs} "
112
+ sh "#{mrbc} #{debug_flag} -o #{main_out} #{libs} "
102
113
  end
103
114
 
104
115
  namespace :test do
@@ -0,0 +1,95 @@
1
+
2
+ class Screen
3
+ SCREEN_X_SIZE = 21
4
+ SCREEN_Y_SIZE = 7
5
+
6
+ attr_accessor :x, :y, :max_x, :max_y
7
+
8
+ def self.setup(max_x, max_y)
9
+ $stdout.close
10
+ Kernel.const_set(:STDOUT, self.new(max_x, max_y))
11
+ $stdout = Kernel::STDOUT
12
+ end
13
+
14
+ def initialize(max_x = SCREEN_X_SIZE, max_y = SCREEN_Y_SIZE)
15
+ @max_x = max_x
16
+ @max_y = max_y
17
+ self.fresh
18
+ end
19
+
20
+ def fresh(value_y = nil, value_x = nil)
21
+ @x = value_x || 0
22
+ @y = value_y || 0
23
+ end
24
+
25
+ def jump_line(value = 1)
26
+ #CommandLinePlatform::Display._puts "=" * 50
27
+ #CommandLinePlatform::Display._puts x
28
+ #CommandLinePlatform::Display._puts y
29
+ #CommandLinePlatform::Display._puts max_x
30
+ #CommandLinePlatform::Display._puts max_y
31
+ #CommandLinePlatform::Display._puts "=" * 50
32
+
33
+ @y += value
34
+ @x = 0
35
+ @y = 0 if (@y > (@max_y-1))
36
+ end
37
+
38
+ def print(*args)
39
+ if n_strings?(args)
40
+ loop_n_strings(*args)
41
+ else
42
+ loop_split_strings(*args)
43
+ end
44
+ nil
45
+ end
46
+
47
+ def printf(*args)
48
+ print(sprintf(*args))
49
+ end
50
+
51
+ def puts(*args)
52
+ if n_strings?(args)
53
+ args = args.map {|str| "#{str}\n" }
54
+ else
55
+ args[0] = "#{args[0]}\n"
56
+ end
57
+ print(*args)
58
+ end
59
+
60
+ private
61
+ def loop_split_strings(*args)
62
+ str, value_y, value_x = *args
63
+
64
+ str.lines.each_with_index do |string, index|
65
+ jump_line if string[-1] == "\n"
66
+ string = string.chomp
67
+ if (@x + string.size) < @max_x
68
+ Device::IO.print_line(string, @y, @x)
69
+ @x += string.size
70
+ else
71
+ space = @max_x - @x
72
+ Device::IO.print_line("#{string[0..(space - 1)]}", @y, @x)
73
+ jump_line
74
+ loop_split_strings("#{string[(space)..-1]}")
75
+ end
76
+ end
77
+ end
78
+
79
+ def loop_n_strings(*args)
80
+ args.each { |str| self.print(str) }
81
+ end
82
+
83
+ # various arguments as string, example:
84
+ # puts "12", "23", "34"
85
+ # # or
86
+ # puts "12", 1, 2
87
+ def n_strings?(args)
88
+ if args[0].is_a?(String) && args[1].is_a?(String)
89
+ true
90
+ else
91
+ false
92
+ end
93
+ end
94
+ end
95
+
data/lib/device/io.rb CHANGED
@@ -17,14 +17,67 @@ class Device
17
17
  CANCEL = 0x1B.chr
18
18
  IO_INPUT_NUMBERS = :numbers
19
19
  IO_INPUT_LETTERS = :letters
20
+ IO_INPUT_ALPHA = :alpha
20
21
  IO_INPUT_SECRET = :secret
21
22
  IO_INPUT_DECIMAL = :decimal
22
23
  IO_INPUT_MONEY = :money
24
+ IO_INPUT_MASK = :mask
25
+
26
+ MASK_ALPHA = :alpha
27
+ MASK_LETTERS = :letters
28
+ MASK_NUMBERS = :number
29
+
30
+ DEFAULT_TIMEOUT = 30000
23
31
 
24
32
  NUMBERS = %w(1 2 3 4 5 6 7 8 9 0)
25
33
 
34
+ ONE_LETTERS = "qzQZ _,."
35
+ TWO_LETTERS = "abcABC"
36
+ THREE_LETTERS = "defDEF"
37
+ FOUR_LETTERS = "ghiGHI"
38
+ FIVE_LETTERS = "jklJKL"
39
+ SIX_LETTERS = "mnoMNO"
40
+ SEVEN_LETTERS = "prsPRS"
41
+ EIGHT_LETTERS = "tuvTUV"
42
+ NINE_LETTERS = "wxyWXY"
43
+ ZERO_LETTERS = "spSP"
44
+
45
+ ONE_NUMBER = "1"
46
+ TWO_NUMBER = "2"
47
+ THREE_NUMBER = "3"
48
+ FOUR_NUMBER = "4"
49
+ FIVE_NUMBER = "5"
50
+ SIX_NUMBER = "6"
51
+ SEVEN_NUMBER = "7"
52
+ EIGHT_NUMBER = "8"
53
+ NINE_NUMBER = "9"
54
+ ZERO_NUMBER = "0"
55
+
56
+ ONE_ALPHA = ONE_NUMBER + ONE_LETTERS
57
+ TWO_ALPHA = TWO_NUMBER + TWO_LETTERS
58
+ THREE_ALPHA = THREE_NUMBER + THREE_LETTERS
59
+ FOUR_ALPHA = FOUR_NUMBER + FOUR_LETTERS
60
+ FIVE_ALPHA = FIVE_NUMBER + FIVE_LETTERS
61
+ SIX_ALPHA = SIX_NUMBER + SIX_LETTERS
62
+ SEVEN_ALPHA = SEVEN_NUMBER + SEVEN_LETTERS
63
+ EIGHT_ALPHA = EIGHT_NUMBER + EIGHT_LETTERS
64
+ NINE_ALPHA = NINE_NUMBER + NINE_LETTERS
65
+ ZERO_ALPHA = ZERO_NUMBER + ZERO_LETTERS
66
+
67
+ RANGE_ALPHA = [ONE_ALPHA, TWO_ALPHA, THREE_ALPHA, FOUR_ALPHA, FIVE_ALPHA, SIX_ALPHA, SEVEN_ALPHA, EIGHT_ALPHA, NINE_ALPHA, ZERO_ALPHA]
68
+ RANGE_NUMBER = [ONE_NUMBER, TWO_NUMBER, THREE_NUMBER, FOUR_NUMBER, FIVE_NUMBER, SIX_NUMBER, SEVEN_NUMBER, EIGHT_NUMBER, NINE_NUMBER, ZERO_NUMBER]
69
+ RANGE_LETTERS = [ONE_LETTERS, TWO_LETTERS, THREE_LETTERS, FOUR_LETTERS, FIVE_LETTERS, SIX_LETTERS, SEVEN_LETTERS, EIGHT_LETTERS, NINE_LETTERS, ZERO_LETTERS]
70
+
71
+ KEYS_RANGE = {MASK_ALPHA => RANGE_ALPHA, MASK_LETTERS => RANGE_LETTERS, MASK_NUMBERS => RANGE_NUMBER}
72
+
26
73
  include Device::Helper
27
74
 
75
+ class << self
76
+ attr_accessor :timeout
77
+ end
78
+
79
+ self.timeout = DEFAULT_TIMEOUT
80
+
28
81
  # Restricted to terminals, get strings and numbers.
29
82
  # The switch method between uppercase, lowercase and number characters is to keep pressing a same button quickly. The timeout of this operation is 1 second.
30
83
  #
@@ -40,47 +93,109 @@ class Device
40
93
  #
41
94
  # :label - Sets the label display before currency, eg.: "U$:", "R$:"
42
95
  #
96
+ # :mask - If mode IO_INPUT_MASK a mask should send
97
+ # (only numbers and letters are allowed), eg.: "9999-AAAA"
98
+ #
43
99
  # :mode - Define input modes:
44
100
  #
45
101
  # :numbers (IO_INPUT_NUMBERS) - Only number.
46
- # :letters (IO_INPUT_LETTERS) - Letters and numbers.
102
+ # :letters (IO_INPUT_LETTERS) - Only Letters.
103
+ # :alpha (IO_INPUT_ALPHA) - Letters and numbers.
47
104
  # :secret (IO_INPUT_SECRET) - Secret *.
48
105
  # :decimal (IO_INPUT_DECIMAL) - Decimal input, only number.
49
106
  # :money (IO_INPUT_MONEY) - Money input, only number.
107
+ # :mask (IO_INPUT_MASK) - Custom mask.
50
108
  #
51
109
  # @return [String] buffer read from keyboard
52
110
  def self.get_format(min, max, options = {})
53
- options[:mode] ||= IO_INPUT_LETTERS
54
- if options[:mode] == IO_INPUT_MONEY || options[:mode] == IO_INPUT_DECIMAL
111
+ set_default_format_option(options)
112
+ key = text = ""
55
113
 
56
- text = ""
57
- key = ""
58
-
59
- while key != CANCEL
60
- Device::Display.clear 2
61
- Device::Display.print_line number_to_currency(text, options), 2, 0
62
- key = getc
63
- if key == BACK
64
- text = text[0..-2]
65
- elsif text.size >= max
66
- next
67
- elsif NUMBERS.include? key
68
- text << key
69
- elsif key == ENTER
70
- return text
71
- end
114
+ while key != CANCEL
115
+ Device::Display.clear options[:line]
116
+ Device::Display.print_line format(text, options), options[:line], options[:column]
117
+ key = getc
118
+ if key == BACK
119
+ text = text[0..-2]
120
+ elsif key == ENTER
121
+ return text
122
+ elsif key == F1 || key == DOWN || key == UP
123
+ change_next(text, check_mask_type(text, options))
124
+ next
125
+ elsif text.size >= max
126
+ next
127
+ elsif insert_key?(key, options)
128
+ text << key
72
129
  end
130
+ end
131
+ end
132
+
133
+ def self.set_default_format_option(options)
134
+ options[:mode] ||= IO_INPUT_LETTERS
135
+ options[:line] ||= 2
136
+ options[:column] ||= 0
137
+
138
+ if options[:mask]
139
+ options[:mask_clean] = options[:mask].chars.reject{|ch| ch.match(/[^0-9A-Za-z]/) }.join
140
+ end
141
+ end
142
+
143
+ def self.check_mask_type(text, options)
144
+ if options[:mode] == Device::IO::IO_INPUT_ALPHA
145
+ Device::IO::MASK_ALPHA
146
+ elsif options[:mode] == Device::IO::IO_INPUT_LETTERS
147
+ Device::IO::MASK_LETTERS
148
+ elsif options[:mode] == Device::IO::IO_INPUT_MASK
149
+ options[:mask_clean][text.length - 1].match(/[0-9]/) ? Device::IO::MASK_NUMBERS : Device::IO::MASK_LETTERS
73
150
  else
74
- get_string(min, max, options[:mode])
151
+ Device::IO::MASK_ALPHA
152
+ end
153
+ end
154
+
155
+ def self.change_next(text, mask_type = Device::IO::MASK_ALPHA)
156
+ char = text[-1]
157
+ if char && (range = KEYS_RANGE[mask_type].detect { |range| range.include?(char) })
158
+ index = range.index(char)
159
+ new_value = range[index+1]
160
+ if new_value
161
+ text[-1] = new_value
162
+ else
163
+ text[-1] = range[0]
164
+ end
75
165
  end
166
+ text
76
167
  end
77
168
 
78
169
  # Read 1 byte on keyboard, wait until be pressed
79
170
  #
80
171
  # @param timeout [Fixnum] Timeout in milliseconds to wait for key.
172
+ # If not sent the default timeout is 30_000.
173
+ # If nil should be blocking.
81
174
  #
82
175
  # @return [String] key read from keyboard
83
- def self.getc(timeout = 0); super(timeout); end
176
+ def self.getc(timeout = self.timeout); super(timeout); end
177
+
178
+ def self.format(string, options)
179
+ if options[:mode] == IO_INPUT_MONEY || options[:mode] == IO_INPUT_DECIMAL
180
+ number_to_currency(string, options)
181
+ elsif options[:mode] == IO_INPUT_SECRET
182
+ "*" * string.size
183
+ elsif options[:mode] == IO_INPUT_MASK
184
+ string.to_mask(options[:mask])
185
+ else
186
+ string
187
+ end
188
+ end
189
+
190
+ def self.insert_key?(key, options)
191
+ if options[:mode] == IO_INPUT_MONEY || options[:mode] == IO_INPUT_DECIMAL || options[:mode] == IO_INPUT_NUMBERS
192
+ NUMBERS.include?(key)
193
+ elsif options[:mode] != IO_INPUT_NUMBERS && options[:mode] != IO_INPUT_MONEY && options[:mode] != IO_INPUT_DECIMAL
194
+ true
195
+ else
196
+ false
197
+ end
198
+ end
84
199
  end
85
200
  end
86
201
 
@@ -91,14 +91,17 @@ class Device
91
91
  end
92
92
 
93
93
  def self.attach
94
- Device::Network.init(*self.config)
95
- ret = Device::Network.connect
96
- ret = Device::Network.connected? if ret != SUCCESS
97
- while(ret == PROCESSING)
98
- ret = Device::Network.connected?
99
- end
100
- if ret == SUCCESS && (wifi? || ethernet?)
101
- Device::Network.dhcp_client(20000)
94
+ ret = Device::Network.connected?
95
+ if ret != SUCCESS
96
+ ret = Device::Network.init(*self.config)
97
+ ret = Device::Network.connect
98
+ ret = Device::Network.connected? if ret != SUCCESS
99
+ while(ret == PROCESSING)
100
+ ret = Device::Network.connected?
101
+ end
102
+ if ret == SUCCESS && (wifi? || ethernet?)
103
+ Device::Network.dhcp_client(20000)
104
+ end
102
105
  end
103
106
  ret
104
107
  end
@@ -57,7 +57,7 @@ class Device
57
57
  date = datetime.sub(" ", "-").split("-")
58
58
  Device::Display.print_line("#{date[1]}/#{date[0]}/#{date[2]} #{date[3]}", 0)
59
59
  Device::Display.print_line("#{message}", 2)
60
- getc(0)
60
+ getc nil
61
61
  }
62
62
  end
63
63
 
@@ -1,6 +1,6 @@
1
1
 
2
2
  class Device
3
- class Print
3
+ class Printer
4
4
  RET_OK = 0
5
5
  ERR_PRN_BUSY = -3701 # Printer busy
6
6
  ERR_PRN_PAPEROUT = -3702 # Out of paper
@@ -144,6 +144,18 @@ class Device
144
144
  self.adapter.puts(string)
145
145
  end
146
146
 
147
+ # Write text on print buffer changing the size only for this print.
148
+ # Big size is (24, 64, 64, 64)
149
+ #
150
+ # @param string [String] Text to be printed.
151
+ #
152
+ # @return [NilClass] Allways returns nil.
153
+ def self.print_big(string)
154
+ size(24, 48, 48, 48)
155
+ self.adapter.print(string)
156
+ size
157
+ end
158
+
147
159
  # Print bmp file.
148
160
  #
149
161
  # Details:
@@ -34,6 +34,8 @@ class Device
34
34
  "notification_stream_timeout" => "",
35
35
  "cw_switch_version" => "",
36
36
  "cw_pos_timezone" => "",
37
+ "uclreceivetimeout" => "0",
38
+ "iso8583_recv_tries" => "0",
37
39
  "company_name" => ""
38
40
  }
39
41
 
data/lib/device/system.rb CHANGED
@@ -47,7 +47,11 @@ class Device
47
47
  end
48
48
 
49
49
  def self.restart
50
- adapter.restart
50
+ adapter.reboot
51
+ end
52
+
53
+ def self.reboot
54
+ adapter.reboot
51
55
  end
52
56
 
53
57
  def self.app
@@ -1,6 +1,6 @@
1
1
 
2
2
  class Device
3
- API_VERSION="0.4.12"
3
+ API_VERSION="0.4.15"
4
4
 
5
5
  def self.api_version
6
6
  Device::API_VERSION
data/lib/ext/string.rb ADDED
@@ -0,0 +1,9 @@
1
+ class String
2
+ def to_mask(mask_string)
3
+ mask_clean = mask_string.chars.reject{|ch| ch.match(/[^0-9A-Za-z]/) }.join
4
+
5
+ str = mask_string.chars.map{|s| s.match(/[0-9A-Za-z]/) ? "%s" : s }.join
6
+ str % self.ljust(mask_clean.size, " ").chars
7
+ end
8
+ end
9
+
@@ -75,6 +75,11 @@ module ISO8583
75
75
  LLVAR_Z.length = LL
76
76
  LLVAR_Z.codec = Track2
77
77
 
78
+ # Two byte variable length ASCII numeral, payload Track2 data
79
+ Z = Field.new
80
+ Z.length = LL
81
+ Z.codec = Track2
82
+
78
83
  # Two byte variable length ASCII numeral, payload ASCII, fixed length, zeropadded (right)
79
84
  LLVAR_AN = Field.new
80
85
  LLVAR_AN.length = LL
@@ -85,6 +90,11 @@ module ISO8583
85
90
  LLVAR_ANS.length = LL
86
91
  LLVAR_ANS.codec = ANS_Codec
87
92
 
93
+ # Thre byte variable length ASCII numeral, payload Track2 data
94
+ LLLVAR_Z = Field.new
95
+ LLLVAR_Z.length = LLL
96
+ LLLVAR_Z.codec = Track2
97
+
88
98
  # Three byte variable length ASCII numeral, payload ASCII, fixed length, zeropadded (right)
89
99
  LLLVAR_AN = Field.new
90
100
  LLLVAR_AN.length = LLL
@@ -113,6 +123,12 @@ module ISO8583
113
123
  sprintf("%0#{len}d", val)
114
124
  }
115
125
 
126
+ XN = BCDField.new
127
+ XN.codec = ASCII_Number
128
+ XN.padding = lambda {|val, len|
129
+ sprintf("%0#{len}d", val)
130
+ }
131
+
116
132
  N_BCD = BCDField.new
117
133
  N_BCD.codec = Packed_Number
118
134
 
@@ -171,5 +187,8 @@ module ISO8583
171
187
  Hhmmss = Field.new
172
188
  Hhmmss.codec = HhmmssCodec
173
189
  Hhmmss.length = 6
190
+
191
+ # Unknown
192
+ UNKNOWN = Field.new
174
193
  end
175
194
 
@@ -0,0 +1,47 @@
1
+
2
+ module ISO8583
3
+ class FileParser
4
+ PATH_DEFAULT = "/shared/bitmap.dat"
5
+
6
+ def self.mount_parameters(data)
7
+ if data[3].match(/[0-9]/)
8
+ [data[1].to_i, "", ISO8583.const_get(data[2]), {:length => data[3].to_i}]
9
+ else
10
+ [data[1].to_i, "", ISO8583.const_get("#{data[3]}_#{data[2]}")]
11
+ end
12
+ end
13
+
14
+ def create_mti(klass, mti_format, mti_messages)
15
+ klass.mti_format *mti_format
16
+ mti_messages.each do |number, description|
17
+ klass.mti number, description
18
+ end
19
+ end
20
+
21
+ def parse_file(filepath)
22
+ return [] unless File.exists?(path)
23
+ file = File.open(path, "r")
24
+
25
+ file.readlines.inject([]) do |array, line|
26
+ data = line.match(/([0-9]+)=\"ATT_([a-zA-Z]+);([0-9A-Z]+)/)
27
+ next(array) unless data
28
+ array << mount_parameters(data)
29
+ end
30
+ ensure
31
+ file.close
32
+ end
33
+
34
+ def self.build_klass(mti_format, mti_messages, filepath = PATH_DEFAULT)
35
+ Class.new(ISO8583::Message) do |klass|
36
+ klass.include ISO8583
37
+ #klass.mti_format ISO8583::N, :length => 4
38
+ #klass.mti 200, "Authorization Request Acquirer Gateway"
39
+ create_mti(klass, mti_format, mti_messages)
40
+
41
+ parse_file(filepath).each do |parameters|
42
+ klass.bmp(*parameters)
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
data/out/da_funk.mrb CHANGED
Binary file
@@ -40,4 +40,46 @@ class DisplayTest < DaFunk::Test.case
40
40
  assert_equal nil, puts("test", 0)
41
41
  assert_equal nil, puts("test", 0, 0)
42
42
  end
43
+
44
+ def test_kernel_puts_break_line
45
+ $stdout.fresh
46
+ assert_equal nil, puts("\n")
47
+ assert_equal 0, $stdout.x
48
+ assert_equal 2, $stdout.y
49
+ assert_equal nil, puts("")
50
+ assert_equal 0, $stdout.x
51
+ assert_equal 3, $stdout.y
52
+ end
53
+
54
+ def test_kernel_puts_string_20_plus_1
55
+ $stdout.fresh
56
+ assert_equal nil, puts("12345678901234567890")
57
+ assert_equal 20, $stdout.x
58
+ assert_equal 1, $stdout.y
59
+ assert_equal nil, puts("1")
60
+ assert_equal 1, $stdout.x
61
+ assert_equal 2, $stdout.y
62
+ end
63
+
64
+ def test_kernel_puts_string_21
65
+ $stdout.fresh
66
+ assert_equal nil, puts("123456789012345678901")
67
+ assert_equal 0, $stdout.x
68
+ assert_equal 2, $stdout.y
69
+ end
70
+
71
+ def test_kernel_puts_string_43
72
+ $stdout.fresh
73
+ assert_equal nil, puts("1234567890123456789012345678901234567890123")
74
+ assert_equal 1, $stdout.x
75
+ assert_equal 3, $stdout.y
76
+ end
77
+
78
+ def test_kernel_puts_string_22
79
+ $stdout.fresh
80
+ assert_equal nil, puts("1234567890123456789012")
81
+ assert_equal 1, $stdout.x
82
+ assert_equal 2, $stdout.y
83
+ end
43
84
  end
85
+
@@ -0,0 +1,134 @@
1
+
2
+ class IOTest < DaFunk::Test.case
3
+ def test_io_change_next_alphanumeric_mask
4
+ text = "TES8"
5
+ assert_equal "TESt", Device::IO.change_next(text)
6
+ assert_equal "TESu", Device::IO.change_next(text)
7
+ assert_equal "TESv", Device::IO.change_next(text)
8
+ assert_equal "TEST", Device::IO.change_next(text)
9
+ assert_equal "TESU", Device::IO.change_next(text)
10
+ assert_equal "TESV", Device::IO.change_next(text)
11
+ assert_equal "TES8", Device::IO.change_next(text)
12
+ end
13
+
14
+ def test_io_change_next_number_mask
15
+ text = "TES8"
16
+ assert_equal "TES8", Device::IO.change_next(text, :number)
17
+ assert_equal "TES8", Device::IO.change_next(text, :number)
18
+ end
19
+
20
+ def test_io_change_next_letters_mask
21
+ text = "TESt"
22
+ assert_equal "TESu", Device::IO.change_next(text, :letters)
23
+ assert_equal "TESv", Device::IO.change_next(text, :letters)
24
+ assert_equal "TEST", Device::IO.change_next(text, :letters)
25
+ assert_equal "TESU", Device::IO.change_next(text, :letters)
26
+ assert_equal "TESV", Device::IO.change_next(text, :letters)
27
+ assert_equal "TESt", Device::IO.change_next(text, :letters)
28
+ end
29
+
30
+ def test_io_insert_key_number
31
+ assert Device::IO.insert_key?("1", {:mode => Device::IO::IO_INPUT_NUMBERS})
32
+ end
33
+
34
+ def test_io_insert_key_decimal
35
+ assert Device::IO.insert_key?("1", {:mode => Device::IO::IO_INPUT_DECIMAL})
36
+ end
37
+
38
+ def test_io_insert_key_money
39
+ assert Device::IO.insert_key?("1", {:mode => Device::IO::IO_INPUT_MONEY})
40
+ end
41
+
42
+ def test_io_insert_key_number_false
43
+ assert_equal false, Device::IO.insert_key?("a", {:mode => Device::IO::IO_INPUT_NUMBERS})
44
+ end
45
+
46
+ def test_io_insert_key_decimal_false
47
+ assert_equal false, Device::IO.insert_key?("a", {:mode => Device::IO::IO_INPUT_DECIMAL})
48
+ end
49
+
50
+ def test_io_insert_key_money_false
51
+ assert_equal false, Device::IO.insert_key?("a", {:mode => Device::IO::IO_INPUT_MONEY})
52
+ end
53
+
54
+ def test_io_format_string_to_money
55
+ options = {:mode => Device::IO::IO_INPUT_MONEY}
56
+ assert_equal "10,000.00", Device::IO.format("1000000", options)
57
+ end
58
+
59
+ def test_io_format_string_to_decimal
60
+ options = {:mode => Device::IO::IO_INPUT_DECIMAL}
61
+ assert_equal "10,000.00", Device::IO.format("1000000", options)
62
+ end
63
+
64
+ def test_io_format_string_to_secret
65
+ options = {:mode => Device::IO::IO_INPUT_SECRET}
66
+ assert_equal "*******", Device::IO.format("1000000", options)
67
+ end
68
+
69
+ def test_io_set_default_format_option
70
+ options = {}
71
+ options_default = {:mode => Device::IO::IO_INPUT_LETTERS, :line => 2, :column => 0}
72
+ Device::IO.set_default_format_option(options)
73
+ assert_equal options_default, options
74
+ end
75
+
76
+ def test_io_set_default_format_option_for_mask
77
+ options = {:mode => Device::IO::IO_INPUT_MASK, :mask => "999-AAA-999/99.99"}
78
+ options_default = {
79
+ :mode => Device::IO::IO_INPUT_MASK,
80
+ :mask_clean => "999AAA9999999",
81
+ :mask => "999-AAA-999/99.99",
82
+ :line => 2, :column => 0
83
+ }
84
+ Device::IO.set_default_format_option(options)
85
+ assert_equal options_default, options
86
+ end
87
+
88
+ def test_io_check_mask_type_alpha
89
+ options = { :mode => Device::IO::IO_INPUT_ALPHA }
90
+ assert_equal Device::IO::MASK_ALPHA, Device::IO.check_mask_type("", options)
91
+ end
92
+
93
+ def test_io_check_mask_type_number
94
+ options = { :mode => Device::IO::IO_INPUT_LETTERS }
95
+ assert_equal Device::IO::MASK_LETTERS, Device::IO.check_mask_type("", options)
96
+ end
97
+
98
+ def test_io_check_mask_type_number_mask
99
+ options = {
100
+ :mode => Device::IO::IO_INPUT_MASK,
101
+ :mask => "999-999/99.99",
102
+ :mask_clean => "9999999999"
103
+ }
104
+ assert_equal Device::IO::MASK_NUMBERS, Device::IO.check_mask_type("", options)
105
+ end
106
+
107
+ def test_io_check_mask_type_letters_mask
108
+ options = {
109
+ :mode => Device::IO::IO_INPUT_MASK,
110
+ :mask => "AAA-AAA/AA.AA",
111
+ :mask_clean => "AAAAAAAAAA"
112
+ }
113
+ assert_equal Device::IO::MASK_LETTERS, Device::IO.check_mask_type("", options)
114
+ end
115
+
116
+ def test_io_check_mask_type_mix_letters_mask
117
+ options = {
118
+ :mode => Device::IO::IO_INPUT_MASK,
119
+ :mask => "999-A99/99.99",
120
+ :mask_clean => "999A999999"
121
+ }
122
+ assert_equal Device::IO::MASK_LETTERS, Device::IO.check_mask_type("111B", options)
123
+ end
124
+
125
+ def test_io_check_mask_type_mix_number_mask
126
+ options = {
127
+ :mode => Device::IO::IO_INPUT_MASK,
128
+ :mask => "AAA-9AA/AA.AA",
129
+ :mask_clean => "AAA9AAAAAA"
130
+ }
131
+ assert_equal Device::IO::MASK_NUMBERS, Device::IO.check_mask_type("SDF4", options)
132
+ end
133
+ end
134
+
@@ -0,0 +1,15 @@
1
+
2
+ class StringTest < DaFunk::Test.case
3
+ def test_to_mask_number
4
+ assert_equal "(12) 341-234", "12341234".to_mask("(99) 999-999")
5
+ end
6
+
7
+ def test_to_mask_letters
8
+ assert_equal "(12) 341-234", "12341234".to_mask("(99) 999-999")
9
+ end
10
+
11
+ def test_to_mask_alpha
12
+ assert_equal "(12) ac34-123", "12ac341234".to_mask("(99) 9AAA-999")
13
+ end
14
+ end
15
+
@@ -8,6 +8,8 @@ class CommandLinePlatform
8
8
  IO = ::IO
9
9
 
10
10
  def self.setup
11
+ CommandLinePlatform::Display.standard_output = STDOUT
12
+ Screen.setup(21, 20)
11
13
  begin
12
14
  require 'cloudwalk_handshake'
13
15
  CloudwalkHandshake.configure!
@@ -27,9 +29,13 @@ class CommandLinePlatform
27
29
  end
28
30
 
29
31
  class Display
32
+ class << self
33
+ attr_accessor :standard_output
34
+ end
35
+
30
36
  def self.print_in_line(buf, row = nil, column = nil)
31
37
  buf = (" " * column) + buf if column != nil && column > 0
32
- puts buf
38
+ _puts buf
33
39
  end
34
40
 
35
41
  def self.clear
@@ -44,6 +50,10 @@ class CommandLinePlatform
44
50
 
45
51
  def self.display_bitmap(path, row, column)
46
52
  end
53
+
54
+ def self._puts(*args)
55
+ standard_output.puts(*args)
56
+ end
47
57
  end
48
58
 
49
59
  class Network
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: da_funk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.12
4
+ version: 0.4.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thiago Scalone
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-03 00:00:00.000000000 Z
11
+ date: 2015-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -99,6 +99,7 @@ files:
99
99
  - lib/da_funk/helper.rb
100
100
  - lib/da_funk/iso8583.rb
101
101
  - lib/da_funk/rake_task.rb
102
+ - lib/da_funk/screen.rb
102
103
  - lib/da_funk/test.rb
103
104
  - lib/device.rb
104
105
  - lib/device/application.rb
@@ -113,7 +114,7 @@ files:
113
114
  - lib/device/notification_callback.rb
114
115
  - lib/device/notification_event.rb
115
116
  - lib/device/params_dat.rb
116
- - lib/device/print.rb
117
+ - lib/device/printer.rb
117
118
  - lib/device/runtime.rb
118
119
  - lib/device/setting.rb
119
120
  - lib/device/support.rb
@@ -123,12 +124,14 @@ files:
123
124
  - lib/device/transaction/iso.rb
124
125
  - lib/device/version.rb
125
126
  - lib/ext/kernel.rb
127
+ - lib/ext/string.rb
126
128
  - lib/file_db.rb
127
129
  - lib/iso8583/bitmap.rb
128
130
  - lib/iso8583/codec.rb
129
131
  - lib/iso8583/exception.rb
130
132
  - lib/iso8583/field.rb
131
133
  - lib/iso8583/fields.rb
134
+ - lib/iso8583/file_parser.rb
132
135
  - lib/iso8583/message.rb
133
136
  - lib/iso8583/util.rb
134
137
  - lib/iso8583/version.rb
@@ -147,9 +150,11 @@ files:
147
150
  - test/unit/device/application_test.rb
148
151
  - test/unit/device/display_test.rb
149
152
  - test/unit/device/helper_test.rb
153
+ - test/unit/device/io_test.rb
150
154
  - test/unit/device/notification_callback_test.rb
151
155
  - test/unit/device/notification_event_test.rb
152
156
  - test/unit/device/notification_test.rb
157
+ - test/unit/ext/string_test.rb
153
158
  - test/unit/file_db_test.rb
154
159
  - test/unit/iso8583_test.rb
155
160
  - test/unit/params_dat_test.rb
@@ -188,9 +193,11 @@ test_files:
188
193
  - test/unit/device/application_test.rb
189
194
  - test/unit/device/display_test.rb
190
195
  - test/unit/device/helper_test.rb
196
+ - test/unit/device/io_test.rb
191
197
  - test/unit/device/notification_callback_test.rb
192
198
  - test/unit/device/notification_event_test.rb
193
199
  - test/unit/device/notification_test.rb
200
+ - test/unit/ext/string_test.rb
194
201
  - test/unit/file_db_test.rb
195
202
  - test/unit/iso8583_test.rb
196
203
  - test/unit/params_dat_test.rb