class Keepassx::Group
Attributes
entries[RW]
parent[R]
Public Class Methods
extract_from_payload(header, payload)
click to toggle source
# File lib/keepassx/group.rb, line 55 def extract_from_payload(header, payload) groups = [] header.groups_count.times { groups << Group.new(payload) } groups end
new(payload)
click to toggle source
Calls superclass method
Keepassx::Fieldable::new
# File lib/keepassx/group.rb, line 34 def initialize(payload) @parent = nil @entries = [] super do # Do some validation raise ArgumentError, "'id' is required (type: integer)" unless valid_integer?(payload[:id]) raise ArgumentError, "'name' is required (type: string)" unless valid_string?(payload[:name]) # First set @parent and @level. # Remove key from payload to not interfere with KeePassX fields format self.parent = payload.delete(:parent) # Build list of fields @fields = build_payload(payload) end end
Public Instance Methods
==(other)
click to toggle source
# File lib/keepassx/group.rb, line 86 def ==(other) return false if other.nil? parent == other.parent && name == other.name && id == other.id && level == other.level && icon == other.icon end
level()
click to toggle source
Redefine level
method to return 0 instead of nil
# File lib/keepassx/group.rb, line 80 def level value = get :level value.nil? ? 0 : value end
parent=(value)
click to toggle source
# File lib/keepassx/group.rb, line 64 def parent=(value) raise ArgumentError, "Expected Keepassx::Group or nil, got #{value.class}" unless valid_parent?(value) if value.is_a?(Keepassx::Group) self.level = value.level + 1 @parent = value elsif value.nil? # Assume, group is located at the top level, in case it has no parent self.level = 0 @parent = nil end end
Private Instance Methods
default_fields()
click to toggle source
# File lib/keepassx/group.rb, line 108 def default_fields @default_fields ||= { id: :unknown, name: :unknown, creation_time: Time.now, last_mod_time: Time.now, last_acc_time: Time.now, expiration_time: Time.local(2999, 12, 28, 23, 59, 59), icon: 1, level: 0, flags: 0, terminator: nil, } end
level=(value)
click to toggle source
Redefine level=
to make it private : Setting group level only is a non-sense as it depends on parent group.
# File lib/keepassx/group.rb, line 103 def level=(value) set :level, value end
valid_parent?(object)
click to toggle source
# File lib/keepassx/group.rb, line 124 def valid_parent?(object) object.is_a?(Keepassx::Group) || object.nil? end