rbzk 0.1.6 → 0.1.8

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.
@@ -42,7 +42,7 @@ module RBZK
42
42
  def save
43
43
  # Create the directory if it doesn't exist
44
44
  FileUtils.mkdir_p(File.dirname(@config_file))
45
-
45
+
46
46
  # Save the configuration
47
47
  File.open(@config_file, 'w') do |f|
48
48
  f.write(YAML.dump(@config))
@@ -68,7 +68,7 @@ module RBZK
68
68
  begin
69
69
  config = YAML.load_file(@config_file)
70
70
  return DEFAULT_CONFIG.merge(config) if config.is_a?(Hash)
71
- rescue => e
71
+ rescue StandardError => e
72
72
  warn "Error loading configuration file: #{e.message}"
73
73
  end
74
74
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module RBZK
4
4
  module Constants
5
- USHRT_MAX = 65535
5
+ USHRT_MAX = 65_535
6
6
 
7
7
  # Command codes
8
8
  CMD_DB_RRQ = 7 # Read in some kind of data from the machine
@@ -121,8 +121,8 @@ module RBZK
121
121
  # Machine constants
122
122
  # These values are in little-endian format when packed
123
123
  # 0x5050 = 'PP' in ASCII when packed as '<H'
124
- MACHINE_PREPARE_DATA_1 = 20560 # 0x5050 = 'P' + 'P'*256 in little-endian
124
+ MACHINE_PREPARE_DATA_1 = 20_560 # 0x5050 = 'P' + 'P'*256 in little-endian
125
125
  # 0x7D82 = 0x827D in little-endian format
126
- MACHINE_PREPARE_DATA_2 = 32130 # 0x7D82
126
+ MACHINE_PREPARE_DATA_2 = 32_130 # 0x7D82
127
127
  end
128
128
  end
@@ -4,19 +4,25 @@ module RBZK
4
4
  class ZKError < StandardError; end
5
5
 
6
6
  class ZKNetworkError < ZKError
7
- def initialize(msg = "Network error")
7
+ def initialize(msg = 'Network error')
8
8
  super
9
9
  end
10
10
  end
11
11
 
12
12
  class ZKErrorConnection < ZKError
13
- def initialize(msg = "Connection error")
13
+ def initialize(msg = 'Connection error')
14
14
  super
15
15
  end
16
16
  end
17
17
 
18
18
  class ZKErrorResponse < ZKError
19
- def initialize(msg = "Invalid response")
19
+ def initialize(msg = 'Invalid response')
20
+ super
21
+ end
22
+ end
23
+
24
+ class ZKErrorExists < ZKError
25
+ def initialize(msg = 'Data already exists')
20
26
  super
21
27
  end
22
28
  end
data/lib/rbzk/finger.rb CHANGED
@@ -4,7 +4,7 @@ module RBZK
4
4
  class Finger
5
5
  attr_accessor :uid, :fid, :valid, :template, :size
6
6
 
7
- def initialize(uid, fid, valid, template = "")
7
+ def initialize(uid, fid, valid, template = '')
8
8
  @uid = uid
9
9
  @fid = fid
10
10
  @valid = valid
data/lib/rbzk/user.rb CHANGED
@@ -4,7 +4,7 @@ module RBZK
4
4
  class User
5
5
  attr_accessor :uid, :user_id, :name, :privilege, :password, :group_id, :card
6
6
 
7
- @@encoding = "UTF-8"
7
+ @@encoding = 'UTF-8'
8
8
 
9
9
  def self.encoding=(encoding)
10
10
  @@encoding = encoding
@@ -17,7 +17,7 @@ module RBZK
17
17
  # Match Python's User constructor exactly
18
18
  # In Python:
19
19
  # def __init__(self, uid, name, privilege, password='', group_id='', user_id='', card=0):
20
- def initialize(uid = 0, name = "", privilege = 0, password = "", group_id = "", user_id = "", card = 0)
20
+ def initialize(uid = 0, name = '', privilege = 0, password = '', group_id = '', user_id = '', card = 0)
21
21
  @uid = uid
22
22
  @name = name
23
23
  @privilege = privilege
@@ -30,20 +30,20 @@ module RBZK
30
30
  # Pack the user data into a binary string for ZK6 devices (size 29)
31
31
  def repack29
32
32
  [2, @uid, @privilege].pack('CS<C') +
33
- @password.encode(@@encoding, invalid: :replace, undef: :replace).ljust(5, "\x00")[0...5] +
34
- @name.encode(@@encoding, invalid: :replace, undef: :replace).ljust(8, "\x00")[0...8] +
35
- [@card, 0, @group_id.to_i, 0, @user_id.to_i].pack('L<CS<S<L<')
33
+ @password.encode(@@encoding, invalid: :replace, undef: :replace).ljust(5, "\x00")[0...5] +
34
+ @name.encode(@@encoding, invalid: :replace, undef: :replace).ljust(8, "\x00")[0...8] +
35
+ [@card, 0, @group_id.to_i, 0, @user_id.to_i].pack('L<CS<S<L<')
36
36
  end
37
37
 
38
38
  # Pack the user data into a binary string for ZK8 devices (size 73)
39
39
  def repack73
40
40
  [2, @uid, @privilege].pack('CS<C') +
41
- @password.encode(@@encoding, invalid: :replace, undef: :replace).ljust(8, "\x00")[0...8] +
42
- @name.encode(@@encoding, invalid: :replace, undef: :replace).ljust(24, "\x00")[0...24] +
43
- [@card, 1].pack('L<C') +
44
- @group_id.to_s.encode(@@encoding, invalid: :replace, undef: :replace).ljust(7, "\x00")[0...7] +
45
- "\x00" +
46
- @user_id.to_s.encode(@@encoding, invalid: :replace, undef: :replace).ljust(24, "\x00")[0...24]
41
+ @password.encode(@@encoding, invalid: :replace, undef: :replace).ljust(8, "\x00")[0...8] +
42
+ @name.encode(@@encoding, invalid: :replace, undef: :replace).ljust(24, "\x00")[0...24] +
43
+ [@card, 1].pack('L<C') +
44
+ @group_id.to_s.encode(@@encoding, invalid: :replace, undef: :replace).ljust(7, "\x00")[0...7] +
45
+ "\x00" +
46
+ @user_id.to_s.encode(@@encoding, invalid: :replace, undef: :replace).ljust(24, "\x00")[0...24]
47
47
  end
48
48
 
49
49
  # Check if the user is disabled
data/lib/rbzk/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RBZK
4
- VERSION = '0.1.6'
4
+ VERSION = '0.1.8'
5
5
  end