da_funk 0.7.3 → 0.7.4

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: c3c811383a895b6f570aff6a6fc1ddef9f913b74
4
- data.tar.gz: e658fda25cc08e9833f87a22edec99c1ca411ae1
3
+ metadata.gz: bc105970da76479f80dfd8fe8e9fb52fe3ccac64
4
+ data.tar.gz: ed5202243e934b45fd4c198b960c22b7a6adaf17
5
5
  SHA512:
6
- metadata.gz: 84a36363e0377b8482c59d446d485765594e41cff1ebc5e3485509b86abf8f6d24022a941af9ca1939631969a21a2183f101586258a62e534217386d227512ab
7
- data.tar.gz: 88119e6f2b45f177ffb925a4003ddab086a8b4ac4dc13bd772c50ad678961e6ead4017b4aabcbe2c19e6baddbe339208cccf84efc97ee571ad1701289c4e5d60
6
+ metadata.gz: 47410c3d8226b401f04bf590da73b28b81a9f1e57aba7a2f2d269723931ea12c48178e006fbf48692b455ce52d337de00b271570130f5e6dad6bbbc7840f682b
7
+ data.tar.gz: d0171d01bee46fa4971632a08d4899031c95df6d7a5aa07f511a9d7959115ee44833fd807f56cf3d41d0af2fa3b6e14b31318077ab329be23cb999e54fb8a7ed
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- da_funk (0.7.3)
4
+ da_funk (0.7.4)
5
5
  bundler (~> 1.7)
6
6
  cloudwalk_handshake (~> 0.5)
7
7
  posxml_parser (~> 0.6)
@@ -11,9 +11,9 @@ PATH
11
11
  GEM
12
12
  remote: https://rubygems.org/
13
13
  specs:
14
- cloudwalk_handshake (0.5.4)
14
+ cloudwalk_handshake (0.6.0)
15
15
  funky-simplehttp (0.4.4)
16
- posxml_parser (0.7.10)
16
+ posxml_parser (0.9.0)
17
17
  rake (10.5.0)
18
18
  yard (0.8.7.6)
19
19
 
@@ -1,5 +1,27 @@
1
1
  # DaFunk
2
2
 
3
+ ### 0.7.4 - 2016-04-15 - Small changes
4
+
5
+ - Add timer type EventListener.
6
+ - Change attach helper to check if Network is configured.
7
+ - Add key ALPHA to change between alpha chars on get_format.
8
+ - Store response from open in Magnetic object.
9
+ - Log error if exception error in file download.
10
+ - Bug fix in key value parse at FileDb supporting more than one “=“.
11
+ - Bugfix ISO8583 exception handler.
12
+ - Refactoring ScreenFlow
13
+ - Rename add method to screen.
14
+ - Remove order, now the order is defined by the screen method call order.
15
+ - Add screen_methods and screen attributes.
16
+ - Add support for setup method, to be called every time before start a screen.
17
+ - Add support for line and column on I18n.pt method.
18
+ - Add support for crc generation from a file.
19
+ - Refactoring download method from ParamsDat class rename tried variable for attempt.
20
+ - Add Device::System.update.
21
+ - Refactoring Crypto crc’s functions to use internal implementation in C from Device if available.
22
+ - Refactoring StatusBar battery display and add support to power_supply from Device.
23
+ - Fix String#integer? to work mRuby 1.2.
24
+
3
25
  ### 0.7.3 - 2016-04-15 - Small changes
4
26
 
5
27
  - Implement NilClass#to_big.
@@ -12,7 +12,7 @@ module DaFunk
12
12
 
13
13
  def dispatch(result)
14
14
  return if result.nil?
15
- Device::Display.clear
15
+ bind.setup
16
16
  route(check(bind.instance_exec(result, &block)))
17
17
  end
18
18
 
@@ -1,6 +1,7 @@
1
1
  module DaFunk
2
2
  class EventHandler
3
3
  attr_reader :option, :type
4
+ attr_accessor :timer
4
5
 
5
6
  def initialize(type, option, &block)
6
7
  @type = type
@@ -10,12 +11,24 @@ module DaFunk
10
11
  end
11
12
 
12
13
  def register
14
+ self.schedule_timer
13
15
  EventListener.add_handler(self)
14
16
  end
15
17
 
16
18
  def perform(*parameter)
19
+ self.schedule_timer
17
20
  @perform_block.call(*parameter)
18
21
  end
22
+
23
+ def schedule_timer
24
+ if self.option.is_a?(Hash) && self.option.include?(:minutes)
25
+ self.timer = Time.now + (self.option[:minutes].to_i * 60)
26
+ end
27
+ end
28
+
29
+ def execute?
30
+ self.timer < Time.now if self.timer
31
+ end
19
32
  end
20
33
  end
21
34
 
@@ -40,7 +40,7 @@ module DaFunk
40
40
  end
41
41
 
42
42
  def delete
43
- self.finish if sel.started?
43
+ self.finish if self.started?
44
44
  EventListener.delete(self)
45
45
  end
46
46
 
@@ -48,8 +48,11 @@ module DaFunk
48
48
  if block_given?
49
49
  @block_start = block
50
50
  else
51
- @started = true
52
- @block_start.call if @block_start
51
+ if @block_start
52
+ @started = @block_start.call
53
+ else
54
+ @started = true
55
+ end
53
56
  end
54
57
  end
55
58
 
@@ -57,7 +60,7 @@ module DaFunk
57
60
  if block_given?
58
61
  @block_check = block
59
62
  else
60
- if @block_check && ! self.handlers.empty?
63
+ if @block_check && ! self.handlers.empty? && self.started?
61
64
  @block_check.call
62
65
  end
63
66
  end
@@ -16,8 +16,9 @@ module DaFunk
16
16
  def initialize(name, crc)
17
17
  @crc = crc
18
18
  @original = name
19
- @remote = @original.sub("#{Device::Setting.company_name}_", "")
20
- @name = @original.sub("#{Device::Setting.company_name}_", "").split(".").first
19
+ company = check_company(name)
20
+ @remote = @original.sub("#{company}_", "")
21
+ @name = @original.sub("#{company}_", "").split(".").first
21
22
  @file = "#{FILEPATH}/#{@remote}"
22
23
  @crc_local = @crc if File.exists?(@file)
23
24
  end
@@ -62,6 +63,10 @@ module DaFunk
62
63
  end
63
64
 
64
65
  private
66
+ def check_company(name)
67
+ name.split("_", 2)[0]
68
+ end
69
+
65
70
  def remove_company(name)
66
71
  name.split("_")[1..-1].join("_")
67
72
  end
@@ -16,19 +16,25 @@ module DaFunk
16
16
 
17
17
  def attach
18
18
  Device::Display.clear
19
- I18n.pt(:attach_connecting)
20
- if Device::Network.connected? < 0
21
- if (ret = Device::Network.attach) == 0
22
- I18n.pt(:attach_connected)
19
+ if Device::Network.configured?
20
+ I18n.pt(:attach_connecting)
21
+ if Device::Network.connected? < 0
22
+ if (ret = Device::Network.attach) == 0
23
+ I18n.pt(:attach_connected)
24
+ else
25
+ I18n.pt(:attach_fail, :args => [ret.to_s])
26
+ sleep 4
27
+ return false
28
+ end
23
29
  else
24
- I18n.pt(:attach_fail, :args => [ret.to_s])
25
- sleep 4
26
- return false
30
+ I18n.pt(:attach_already_connected)
27
31
  end
32
+ true
28
33
  else
29
- I18n.pt(:attach_already_connected)
34
+ I18n.pt(:attach_device_not_configured)
35
+ sleep(2)
36
+ false
30
37
  end
31
- true
32
38
  end
33
39
 
34
40
  def check_download_error(ret)
@@ -6,14 +6,16 @@ module DaFunk
6
6
  SLOT_BATTERY = 7
7
7
 
8
8
  BATTERY_IMAGES = {
9
- 0 => "./shared/battery0.png",
10
- 1 => "./shared/battery25.png",
11
- 2 => "./shared/battery50.png",
12
- 3 => "./shared/battery75.png",
13
- 4 => "./shared/battery100.png",
14
- 5 => "./shared/battery0c.png",
15
- 6 => "./shared/battery100c.png",
16
- 7 => nil
9
+ 0..24 => "./shared/battery0.png",
10
+ 25..49 => "./shared/battery25.png",
11
+ 50..74 => "./shared/battery50.png",
12
+ 75..99 => "./shared/battery75.png",
13
+ 100..100 => "./shared/battery100.png"
14
+ }
15
+
16
+ BATTERY_CHARGE_IMAGES = {
17
+ 50 => "./shared/battery0c.png",
18
+ 100 => "./shared/battery100c.png"
17
19
  }
18
20
 
19
21
  WIFI_IMAGES = {
@@ -33,7 +35,7 @@ module DaFunk
33
35
  }
34
36
 
35
37
  class << self
36
- attr_accessor :status_timeout, :signal, :battery
38
+ attr_accessor :status_timeout, :signal, :battery, :power
37
39
  end
38
40
 
39
41
  def self.check
@@ -58,11 +60,18 @@ module DaFunk
58
60
  end
59
61
 
60
62
  def self.change_battery
61
- bat = Device::System.battery
62
- if self.battery != bat
63
+ bat = Device::System.battery
64
+ dock = Device::System.power_supply
65
+ if self.battery != bat || self.power != dock
63
66
  self.battery = bat
64
- Device::Display.print_status_bar(
65
- SLOT_BATTERY, get_image_path(:battery, self.battery))
67
+ self.power = dock
68
+ if self.power
69
+ Device::Display.print_status_bar(
70
+ SLOT_BATTERY, get_image_path(:battery_charge, self.battery))
71
+ else
72
+ Device::Display.print_status_bar(
73
+ SLOT_BATTERY, get_image_path(:battery, self.battery))
74
+ end
66
75
  end
67
76
  end
68
77
 
@@ -74,7 +83,9 @@ module DaFunk
74
83
  when :wifi
75
84
  WIFI_IMAGES.each {|k,v| return v if k.include? sig }
76
85
  when :battery
77
- BATTERY_IMAGES[sig]
86
+ BATTERY_IMAGES.each {|k,v| return v if k.include? sig }
87
+ when :battery_charge
88
+ BATTERY_CHARGE_IMAGES[sig]
78
89
  else
79
90
  nil
80
91
  end
@@ -66,7 +66,7 @@ class I18n
66
66
  end
67
67
 
68
68
  def self.pt(symbol, options = {})
69
- puts(t(symbol, options))
69
+ puts(t(symbol, options), options[:line], options[:column])
70
70
  end
71
71
 
72
72
  def self.parse_time(value, time)
@@ -28,7 +28,7 @@ module DaFunk
28
28
  @main_out ||= File.join(out_path, "main.mrb")
29
29
  @test_out ||= File.join(out_path, "test.mrb")
30
30
  @resources ||= FileList['resources/**/*']
31
- @resources_out ||= @resources.pathmap("%{resources,#{out_path}}p")
31
+ @resources_out ||= @resources.pathmap("%{resources,#{File.join(root_path, "out")}}p")
32
32
  @tests_res_out ||= @tests_resources.pathmap("%{test/resources,out}p")
33
33
  @mruby ||= "cloudwalk run"
34
34
  @mrbc = get_mrbc_bin(@mrbc)
@@ -1,24 +1,32 @@
1
1
  module DaFunk
2
2
  class ScreenFlow
3
- attr_accessor :list
3
+ class << self
4
+ attr_accessor :screen_methods, :setup
5
+ end
6
+ attr_reader :screens
4
7
 
5
- def self.add(method, &block)
8
+ def self.screen(method, &block)
9
+ self.screen_methods ||= []
10
+ self.screen_methods << method
6
11
  define_method method do
7
- @list << CallbackFlow.new(self, @list.last, &block)
8
- self
12
+ @screens << CallbackFlow.new(self, @screens.last, &block)
9
13
  end
10
14
  end
11
15
 
12
16
  def initialize
13
- self.list = []
14
- order
17
+ @screens = []
18
+ self.class.screen_methods.each{|method| send(method) }
19
+ end
20
+
21
+ def self.setup(&block)
22
+ define_method(:setup, &block)
15
23
  end
16
24
 
17
- def order
25
+ def setup
18
26
  end
19
27
 
20
28
  def start
21
- first = self.list.first
29
+ first = self.screens.first
22
30
  first.dispatch(true) if first
23
31
  end
24
32
 
@@ -28,3 +36,4 @@ module DaFunk
28
36
  end
29
37
  end
30
38
  end
39
+
@@ -1,4 +1,4 @@
1
1
  module DaFunk
2
- VERSION="0.7.3"
2
+ VERSION="0.7.4"
3
3
  end
4
4
 
@@ -25,8 +25,9 @@ class Device
25
25
  @crc = crc
26
26
  @original = remote
27
27
  @order, @label = split_label(label)
28
- @remote = remote.sub("#{Device::Setting.company_name}_", "")
29
- @name = remote.sub("#{Device::Setting.company_name}_", "").split(".")[0]
28
+ company = check_company(remote)
29
+ @remote = remote.sub("#{company}_", "")
30
+ @name = remote.sub("#{company}_", "").split(".")[0]
30
31
  @file = check_path(@remote)
31
32
  @crc_local = @crc if File.exists?(@file)
32
33
  end
@@ -90,6 +91,10 @@ class Device
90
91
 
91
92
  private
92
93
 
94
+ def check_company(name)
95
+ name.split("_", 2)[0]
96
+ end
97
+
93
98
  def calculate_crc
94
99
  if exists?
95
100
  handle = File.open(file)
@@ -2,6 +2,13 @@
2
2
  class Device
3
3
  class Crypto
4
4
  include DaFunk::Helper
5
+
6
+ def self.adapter
7
+ if Device.const_defined?(:Crypto)
8
+ Device.adapter::Crypto
9
+ end
10
+ end
11
+
5
12
  CCITT_16 = [
6
13
  0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7,
7
14
  0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF,
@@ -45,8 +52,29 @@ class Device
45
52
  end
46
53
 
47
54
  def self.crc16(buf, crc=0)
48
- buf.each_byte{|x| crc = ((crc<<8) ^ CCITT_16[(crc>>8) ^ x])&0xffff}
49
- crc
55
+ if self.adapter.respond_to? :crc16
56
+ self.adapter.crc16(buf, crc)
57
+ else
58
+ buf.each_byte{|x| crc = ((crc<<8) ^ CCITT_16[(crc>>8) ^ x])&0xffff}
59
+ crc
60
+ end
61
+ end
62
+
63
+ def self.file_crc16_hex(path)
64
+ if File.exists?(path)
65
+ crc = 0
66
+ File.open(path) do |file|
67
+ loop do
68
+ break unless buf = file.read(1000)
69
+ crc = self.crc16(buf, crc)
70
+ end
71
+ end
72
+ rjust(crc.to_s(16).upcase, 4, "0")
73
+ else
74
+ "0000"
75
+ end
76
+ ensure
77
+ GC.start
50
78
  end
51
79
  end
52
80
  end
@@ -138,7 +138,7 @@ class Device
138
138
  text = text[0..-2]
139
139
  elsif key == ENTER || key == KEY_TIMEOUT
140
140
  return text
141
- elsif key == F1 || key == DOWN || key == UP
141
+ elsif key == F1 || key == DOWN || key == UP || key == ALPHA
142
142
  change_next(text, check_mask_type(text, options))
143
143
  next
144
144
  elsif text.size >= max
@@ -31,7 +31,7 @@ class Device
31
31
 
32
32
  def initialize
33
33
  @status = STATUS_CLOSE
34
- self.start
34
+ @open = self.start
35
35
  end
36
36
 
37
37
  def start
@@ -69,6 +69,10 @@ class Device
69
69
  @tracks
70
70
  end
71
71
 
72
+ def open?
73
+ @open
74
+ end
75
+
72
76
  def bin?(value)
73
77
  tracks if STATUS_SUCCESSFUL_READ
74
78
  digits = track2.to_s[0..3]
@@ -97,11 +97,16 @@ class Device
97
97
  def self.download
98
98
  if attach
99
99
  parse
100
- ret = try(3) do |tried|
100
+ ret = try(3) do |attempt|
101
101
  Device::Display.clear
102
102
  I18n.pt(:downloading_content, :args => ["PARAMS", 1, 1])
103
103
  ret = Device::Transaction::Download.request_param_file(FILE_NAME)
104
- check_download_error(ret)
104
+ unless check_download_error(ret)
105
+ sleep(2)
106
+ false
107
+ else
108
+ true
109
+ end
105
110
  end
106
111
  parse if ret
107
112
  ret
@@ -140,7 +145,7 @@ class Device
140
145
 
141
146
  def self.update_app(application, index = 1, all = 1, force = false)
142
147
  if attach && application
143
- try(3) do |tried|
148
+ try(3) do |attempt|
144
149
  Device::Display.clear
145
150
  I18n.pt(:downloading_content, :args => [I18n.t(:apps), index, all])
146
151
  ret = check_download_error(application.download(force))
@@ -152,7 +157,7 @@ class Device
152
157
 
153
158
  def self.update_file(file_parameter, index = 1, all = 1, force = false)
154
159
  if attach && file_parameter
155
- try(3) do |tried|
160
+ try(3) do |attempt|
156
161
  Device::Display.clear
157
162
  I18n.pt(:downloading_content, :args => [I18n.t(:files), index, all])
158
163
  ret = check_download_error(file_parameter.download(force))
@@ -13,15 +13,25 @@ class Device
13
13
  ERR_DEV_BUSY = -1005 # Device is busy.
14
14
  ERR_FONT_NOT_EXIST = -1008 # Font does not exist.
15
15
 
16
- DEFAULT_SINGLE_WIDTH = 12
17
- DEFAULT_SINGLE_HEIGHT = 24
18
- DEFAULT_MULTI_WIDTH = 24
19
- DEFAULT_MULTI_HEIGHT = 24
16
+ DEFAULT_SINGLE_WIDTH = 10
17
+ DEFAULT_SINGLE_HEIGHT = 21
18
+ DEFAULT_MULTI_WIDTH = 10
19
+ DEFAULT_MULTI_HEIGHT = 21
20
+
21
+ BMP_SUCCESS = 0
22
+ BMP_FILE_ERROR = -1
23
+ BMP_NOT_MONOCHROME = -3
24
+ BMP_INVALID_WIDTH = -4
25
+ BMP_LSEEK_FAILED = -5
20
26
 
21
27
  def self.adapter
22
28
  Device.adapter::Printer
23
29
  end
24
30
 
31
+ class << self
32
+ attr_accessor :single_width, :single_height, :multi_width, :multi_height
33
+ end
34
+
25
35
  # Initialize Printer device.
26
36
  #
27
37
  # @param singlecode_width [Fixnum] The width control of single code font.
@@ -43,6 +53,12 @@ class Device
43
53
  singlecode_height=DEFAULT_SINGLE_HEIGHT,
44
54
  multicode_width=DEFAULT_MULTI_WIDTH,
45
55
  multicode_height=DEFAULT_MULTI_HEIGHT)
56
+
57
+ self.single_width = singlecode_width
58
+ self.single_height = singlecode_height
59
+ self.multi_width = multicode_width
60
+ self.multi_height = multicode_height
61
+
46
62
  self.adapter.start(singlecode_width, singlecode_height, multicode_width, multicode_height)
47
63
  end
48
64
 
@@ -78,8 +94,8 @@ class Device
78
94
  # @return [Fixnum] RET_OK Success.
79
95
  # @return [Fixnum] ERR_FONT_NOT_EXIST Font does not exist.
80
96
  # @return [Fixnum] ERR_INVALID_PARAM Invalid parameter.
81
- def self.font=(path)
82
- self.adapter.font = path
97
+ def self.set_font(path)
98
+ self.adapter.set_font(path)
83
99
  end
84
100
 
85
101
  # Sets printing gray level.
@@ -132,6 +148,7 @@ class Device
132
148
  #
133
149
  # @return [NilClass] Allways returns nil.
134
150
  def self.print(string)
151
+ self.size(self.single_width, self.single_height, self.multi_width, self.multi_height)
135
152
  self.adapter.print(string)
136
153
  end
137
154
 
@@ -151,9 +168,8 @@ class Device
151
168
  #
152
169
  # @return [NilClass] Allways returns nil.
153
170
  def self.print_big(string)
154
- size(24, 48, 48, 48)
171
+ self.size(18, 36, 18, 36)
155
172
  self.adapter.print(string)
156
- size
157
173
  end
158
174
 
159
175
  # Print bmp file.
@@ -29,15 +29,14 @@ class Device
29
29
  @backlight ||= adapter.backlight
30
30
  end
31
31
 
32
- # Read the battery level.
33
- # 0 Battery voltage low and battery icon blinks. Suggested that do not process transaction, print and wireless communication etc. at this moment. You should recharge the battery immediately to avoid shut down and lost data.
34
- # 1 Battery icon displays 1 grid
35
- # 2 Battery icon displays 2 grids
36
- # 3 Battery icon displays 3 grids
37
- # 4 Battery icon displays 4 grids
38
- # 5 Powered by external power supply and the battery in charging. Battery icon displays form empty to full cycle. The battery status indicator on the bottom of terminal is displaying red
39
- # 6 Powered by external power supply and the battery charging 6 finished. Battery icon displays full grids. The battery status indicator on the bottom of terminal is displaying green.
40
- # 7 Powered by external power supply and has no battery.
32
+ # Check if device is connected to any power supply
33
+ # true Connected
34
+ # false Not Connected
35
+ def self.power_supply
36
+ adapter.power_supply
37
+ end
38
+
39
+ # Read the battery level, return the value in percentage.
41
40
  def self.battery
42
41
  adapter.battery
43
42
  end
@@ -69,6 +68,12 @@ class Device
69
68
  def self.versions
70
69
  adapter.versions
71
70
  end
71
+
72
+ def self.update(path)
73
+ if File.exists? path
74
+ adapter.update(path)
75
+ end
76
+ end
72
77
  end
73
78
  end
74
79
 
@@ -20,6 +20,21 @@ class Device
20
20
  MAPREDUCE_RESPONSE_ERROR = -2
21
21
  IO_ERROR = -3
22
22
 
23
+ def self.check(ret)
24
+ case ret
25
+ when SERIAL_NUMBER_NOT_FOUND
26
+ when FILE_NOT_FOUND
27
+ when FILE_NOT_CHANGE
28
+ return true
29
+ when SUCCESS
30
+ return true
31
+ when COMMUNICATION_ERROR
32
+ when MAPREDUCE_RESPONSE_ERROR
33
+ when IO_ERROR
34
+ end
35
+ false
36
+ end
37
+
23
38
  def self.request_file(remote_path, local_path, crc = nil)
24
39
  download = Device::Transaction::Download.new(Device::System.serial, "", DaFunk::VERSION)
25
40
  download.perform(Device::Network.socket,
@@ -118,7 +133,8 @@ class Device
118
133
  return_code
119
134
  rescue SocketError
120
135
  return COMMUNICATION_ERROR
121
- rescue
136
+ rescue => e
137
+ ContextLog.error(e, e.backtrace)
122
138
  return IO_ERROR
123
139
  end
124
140
 
@@ -13,7 +13,14 @@ class String
13
13
  def integer?
14
14
  return true if self[0] == "0"
15
15
  !!Integer(self)
16
- rescue ArgumentError
16
+ rescue ArgumentError => e
17
+ if e.message[-19..-1] == "too big for integer"
18
+ begin
19
+ return self.to_i.to_s.size == self.size
20
+ rescue
21
+ false
22
+ end
23
+ end
17
24
  return false
18
25
  end
19
26
  end
@@ -19,7 +19,7 @@ class FileDb
19
19
 
20
20
  def parse(text)
21
21
  text.split("\n").compact.each do |line|
22
- key_value = line.split("=")
22
+ key_value = line.split("=", 2)
23
23
  key, value = sanitize(key_value[0]), sanitize(key_value[1])
24
24
  @hash[key] = value unless value.empty?
25
25
  end
@@ -85,9 +85,8 @@ module ISO8583
85
85
  # ASCII_Number
86
86
  ASCII_Number = Codec.new
87
87
  ASCII_Number.encoder= lambda{|num|
88
- enc = num.to_s
89
- raise ISO8583Exception.new("Invalid value: #{enc} must be numeric!") unless enc =~ /^[0-9]*$/
90
- enc
88
+ raise ISO8583Exception.new("Invalid value: #{num} must be numeric!") unless "#{num}" =~ /^[0-9]*$/
89
+ "#{num}"
91
90
  }
92
91
 
93
92
  ASCII_Number.decoder = lambda{|raw|
@@ -95,7 +94,7 @@ module ISO8583
95
94
  }
96
95
 
97
96
  PASS_THROUGH_DECODER = lambda{|str|
98
- str.strip # remove padding
97
+ "#{str.strip}" # remove padding
99
98
  }
100
99
 
101
100
  # Takes a number or str representation of a number and BCD encodes it, e.g.
@@ -137,8 +136,9 @@ module ISO8583
137
136
 
138
137
  ANS_Codec = Codec.new
139
138
  ANS_Codec.encoder = lambda{|str|
140
- raise ISO8583Exception.new("Invalid value: #{str} must be [\\x20-\\x7E]") unless str =~ /^[\x20-\x7E]*$/
141
- str
139
+ #raise ISO8583Exception.new("Invalid value: #{str} must be [A-Za-y0-9 ]") unless str =~ /^[A-Za-z0-9 ]*$/
140
+ #raise ISO8583Exception.new("Invalid value: #{str} must be [\\x20-\\x7E]") unless str =~ /^[\x20-\x7E]*$/
141
+ "#{str}"
142
142
  }
143
143
  ANS_Codec.decoder = PASS_THROUGH_DECODER
144
144
 
@@ -175,8 +175,10 @@ module ISO8583
175
175
  begin
176
176
  dt = DateTime.strptime(date, fmt)
177
177
  dt.strftime(fmt)
178
- rescue
179
- raise ISO8583Exception.new("Invalid format encoding: #{date}, must be #{fmt}.")
178
+ rescue => e
179
+ msg = "Invalid format encoding: #{date}, must be #{fmt}."
180
+ ContextLog.error(e, e.backtrace, msg)
181
+ raise ISO8583Exception.new(msg)
180
182
  end
181
183
  else
182
184
  raise ISO8583Exception.new("Don't know how to encode: #{date.class} to a time.")
@@ -186,8 +188,10 @@ module ISO8583
186
188
  c.decoder = lambda {|str|
187
189
  begin
188
190
  DateTime.strptime(str, fmt)
189
- rescue
190
- raise ISO8583Exception.new("Invalid format decoding: #{str}, must be #{fmt}.")
191
+ rescue => e
192
+ msg = "Invalid format decoding: #{str}, must be #{fmt}."
193
+ ContextLog.error(e, e.backtrace, msg)
194
+ raise ISO8583Exception.new(msg)
191
195
  end
192
196
  }
193
197
 
@@ -38,8 +38,9 @@ module ISO8583
38
38
  rest = raw[len, raw.length]
39
39
  begin
40
40
  real_value = codec.decode(raw_value)
41
- rescue
42
- raise ISO8583ParseException.new($!.message+" (#{name})")
41
+ rescue => e
42
+ ContextLog.error e, e.backtrace
43
+ raise ISO8583ParseException.new(e.message+" (#{name})")
43
44
  end
44
45
 
45
46
  [ real_value, rest ]
@@ -54,8 +55,9 @@ module ISO8583
54
55
  def encode(value)
55
56
  begin
56
57
  encoded_value = codec.encode(value)
57
- rescue ISO8583Exception
58
- raise ISO8583Exception.new($!.message+" (#{name})")
58
+ rescue ISO8583Exception => e
59
+ ContextLog.error(e, e.backtrace, "#{e.message} (#{name})")
60
+ raise ISO8583Exception.new(e.message+" (#{name})")
59
61
  end
60
62
 
61
63
  if padding
@@ -5,6 +5,7 @@
5
5
  #++
6
6
 
7
7
  module ISO8583
8
+ include DaFunk::Helper
8
9
 
9
10
  # This file contains a number of preinstantiated Field definitions. You
10
11
  # will probably need to create own fields in your implementation, please
@@ -120,13 +121,13 @@ module ISO8583
120
121
  N = Field.new
121
122
  N.codec = ASCII_Number
122
123
  N.padding = lambda {|val, len|
123
- sprintf("%0#{len}d", val)
124
+ rjust(val.to_s, len, "0")
124
125
  }
125
126
 
126
127
  XN = BCDField.new
127
128
  XN.codec = ASCII_Number
128
129
  XN.padding = lambda {|val, len|
129
- sprintf("%0#{len}d", val)
130
+ rjust(val.to_s, len, "0")
130
131
  }
131
132
 
132
133
  N_BCD = BCDField.new
@@ -104,6 +104,9 @@ class CommandLinePlatform
104
104
  end
105
105
  end
106
106
 
107
+ class Crypto
108
+ end
109
+
107
110
  def self.version
108
111
  DaFunk::VERSION
109
112
  end
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.7.3
4
+ version: 0.7.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thiago Scalone
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-18 00:00:00.000000000 Z
11
+ date: 2016-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -234,4 +234,3 @@ test_files:
234
234
  - test/unit/iso8583_build_klass.rb
235
235
  - test/unit/iso8583_test.rb
236
236
  - test/unit/params_dat_test.rb
237
- has_rdoc: