Class: RBZK::User
- Inherits:
-
Object
- Object
- RBZK::User
- Defined in:
- lib/rbzk/user.rb
Constant Summary collapse
- @@encoding =
'UTF-8'
Instance Attribute Summary collapse
-
#card ⇒ Object
Returns the value of attribute card.
-
#group_id ⇒ Object
Returns the value of attribute group_id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#password ⇒ Object
Returns the value of attribute password.
-
#privilege ⇒ Object
Returns the value of attribute privilege.
-
#uid ⇒ Object
Returns the value of attribute uid.
-
#user_id ⇒ Object
Returns the value of attribute user_id.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(uid = 0, name = '', privilege = 0, password = '', group_id = '', user_id = '', card = 0) ⇒ User
constructor
Match Python’s User constructor exactly In Python: def __init__(self, uid, name, privilege, password=”, group_id=”, user_id=”, card=0):.
-
#is_disabled? ⇒ Boolean
Check if the user is disabled.
-
#is_enabled? ⇒ Boolean
Check if the user is enabled.
-
#repack29 ⇒ Object
Pack the user data into a binary string for ZK6 devices (size 29).
-
#repack73 ⇒ Object
Pack the user data into a binary string for ZK8 devices (size 73).
- #to_s ⇒ Object
-
#usertype ⇒ Object
Get the user type.
Constructor Details
#initialize(uid = 0, name = '', privilege = 0, password = '', group_id = '', user_id = '', card = 0) ⇒ User
Match Python’s User constructor exactly In Python: def __init__(self, uid, name, privilege, password=”, group_id=”, user_id=”, card=0):
20 21 22 23 24 25 26 27 28 |
# File 'lib/rbzk/user.rb', line 20 def initialize(uid = 0, name = '', privilege = 0, password = '', group_id = '', user_id = '', card = 0) @uid = uid @name = name @privilege = privilege @password = password @group_id = group_id @user_id = user_id @card = card end |
Instance Attribute Details
#card ⇒ Object
Returns the value of attribute card.
5 6 7 |
# File 'lib/rbzk/user.rb', line 5 def card @card end |
#group_id ⇒ Object
Returns the value of attribute group_id.
5 6 7 |
# File 'lib/rbzk/user.rb', line 5 def group_id @group_id end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/rbzk/user.rb', line 5 def name @name end |
#password ⇒ Object
Returns the value of attribute password.
5 6 7 |
# File 'lib/rbzk/user.rb', line 5 def password @password end |
#privilege ⇒ Object
Returns the value of attribute privilege.
5 6 7 |
# File 'lib/rbzk/user.rb', line 5 def privilege @privilege end |
#uid ⇒ Object
Returns the value of attribute uid.
5 6 7 |
# File 'lib/rbzk/user.rb', line 5 def uid @uid end |
#user_id ⇒ Object
Returns the value of attribute user_id.
5 6 7 |
# File 'lib/rbzk/user.rb', line 5 def user_id @user_id end |
Class Method Details
.encoding ⇒ Object
13 14 15 |
# File 'lib/rbzk/user.rb', line 13 def self.encoding @@encoding end |
.encoding=(encoding) ⇒ Object
9 10 11 |
# File 'lib/rbzk/user.rb', line 9 def self.encoding=(encoding) @@encoding = encoding end |
Instance Method Details
#is_disabled? ⇒ Boolean
Check if the user is disabled
50 51 52 |
# File 'lib/rbzk/user.rb', line 50 def is_disabled? (@privilege & 1) != 0 end |
#is_enabled? ⇒ Boolean
Check if the user is enabled
55 56 57 |
# File 'lib/rbzk/user.rb', line 55 def is_enabled? !is_disabled? end |
#repack29 ⇒ Object
Pack the user data into a binary string for ZK6 devices (size 29)
31 32 33 34 35 36 |
# File 'lib/rbzk/user.rb', line 31 def repack29 [2, @uid, @privilege].pack('CS<C') + @password.encode(@@encoding, invalid: :replace, undef: :replace).ljust(5, "\x00")[0...5] + @name.encode(@@encoding, invalid: :replace, undef: :replace).ljust(8, "\x00")[0...8] + [@card, 0, @group_id.to_i, 0, @user_id.to_i].pack('L<CS<S<L<') end |
#repack73 ⇒ Object
Pack the user data into a binary string for ZK8 devices (size 73)
39 40 41 42 43 44 45 46 47 |
# File 'lib/rbzk/user.rb', line 39 def repack73 [2, @uid, @privilege].pack('CS<C') + @password.encode(@@encoding, invalid: :replace, undef: :replace).ljust(8, "\x00")[0...8] + @name.encode(@@encoding, invalid: :replace, undef: :replace).ljust(24, "\x00")[0...24] + [@card, 1].pack('L<C') + @group_id.to_s.encode(@@encoding, invalid: :replace, undef: :replace).ljust(7, "\x00")[0...7] + "\x00" + @user_id.to_s.encode(@@encoding, invalid: :replace, undef: :replace).ljust(24, "\x00")[0...24] end |
#to_s ⇒ Object
64 65 66 |
# File 'lib/rbzk/user.rb', line 64 def to_s "#{@uid} #{@user_id} #{@name} #{@privilege} #{@password} #{@group_id} #{@card}" end |
#usertype ⇒ Object
Get the user type
60 61 62 |
# File 'lib/rbzk/user.rb', line 60 def usertype @privilege & 0xE end |