Class: Keepassx::Group

Inherits:
Fieldable show all
Defined in:
lib/keepassx/group.rb

Instance Attribute Summary collapse

Attributes inherited from Fieldable

#fields

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Fieldable

create_fieldable_methods, #encode, fields, #inspect, #length, set_field_descriptor, #to_hash

Constructor Details

#initialize(payload) ⇒ Group

Returns a new instance of Group.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# 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

Instance Attribute Details

#entriesObject

Returns the value of attribute entries.



31
32
33
# File 'lib/keepassx/group.rb', line 31

def entries
  @entries
end

#parentObject

Returns the value of attribute parent.



32
33
34
# File 'lib/keepassx/group.rb', line 32

def parent
  @parent
end

Class Method Details

.extract_from_payload(header, payload) ⇒ Object



55
56
57
58
59
# File 'lib/keepassx/group.rb', line 55

def extract_from_payload(header, payload)
  groups = []
  header.groups_count.times { groups << Group.new(payload) }
  groups
end

Instance Method Details

#==(other) ⇒ Object



86
87
88
89
90
91
92
93
94
# 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

#levelObject

Redefine #level method to return 0 instead of nil



80
81
82
83
# File 'lib/keepassx/group.rb', line 80

def level
  value = get :level
  value.nil? ? 0 : value
end