Class: Keepassx::Entry

Inherits:
Fieldable show all
Defined in:
lib/keepassx/entry.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) ⇒ Entry

Returns a new instance of Entry.



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/keepassx/entry.rb', line 38

def initialize(payload)
  super do
    # Do some validation
    raise ArgumentError, "'name' is required (type: string)" unless valid_string?(payload[:name])
    raise ArgumentError, "'group_id' is required (type: integer)" unless payload[:group] || valid_integer?(payload[:group_id])

    # First set @group and @group_id.
    # Remove key from payload to not interfere with KeePassX fields format
    self.group = payload.delete(:group)

    # Add group_id key to respect KeePassX fields format
    payload[:group_id] = group.id

    # Build list of fields
    @fields = build_payload(payload)
  end
end

Instance Attribute Details

#groupObject

Returns the value of attribute group.



36
37
38
# File 'lib/keepassx/entry.rb', line 36

def group
  @group
end

Class Method Details

.extract_from_payload(header, payload) ⇒ Object



59
60
61
62
63
# File 'lib/keepassx/entry.rb', line 59

def extract_from_payload(header, payload)
  entries = []
  header.entries_count.times { entries << Entry.new(payload) }
  entries
end