Class: Keepassx::Entry

Inherits:
Object
  • Object
show all
Includes:
Item
Defined in:
lib/keepassx/entry.rb

Constant Summary collapse

FIELD_CLASS =
Keepassx::EntryField
FIELD_MAPPING =
{
    :title       => :title,
    :icon        => :imageid,
    :lastmod     => :last_mod_time,
    :lastaccess  => :last_acc_time,
    :creation    => :creation_time,
    :expire      => :expiration_time,
    :password    => :password,
    :username    => :username,
    :uuid        => :uuid,
    :url         => :url,
    :binary_desc => :binary_desc,
    :binary_data => :binary_data,
    :comment     => :notes,
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Item

#encode, #inspect, #length, #terminator=, #to_hash, #to_xml

Constructor Details

#initialize(payload) ⇒ Entry

Returns a new instance of Entry.



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/keepassx/entry.rb', line 79

def initialize(payload)
  super

  if payload.is_a? StringIO
    decode payload

  elsif payload.is_a? Hash
    fail "'title' is required" if payload[:title].nil?
    fail "'group' is required" if payload[:group].nil?
    self.group = payload[:group]

    fields =  self.class.fields
    data = payload.reject { |k, _| !fields.include? k }
    data[:group_id] = group.id

    @fields = []
    default_fields.merge(data).each do |k, v|
      fail "Unknown field: '#{k}'" unless self.respond_to? "#{k}=", true
      @fields << self.send("#{k}=", v)
    end

  else
    fail "Expecting StringIO or Hash, got #{payload.class}"
  end
end

Instance Attribute Details

#groupObject

Returns the value of attribute group.



106
107
108
# File 'lib/keepassx/entry.rb', line 106

def group
  @group
end

Class Method Details

.extract_from_payload(header, groups, payload) ⇒ Array<Keepassx::Entry>

Create entries from raw data.

Parameters:

  • header (Keepassx::Header)

    Keepassx database header.

  • groups (Array<Keepassx::Group>)

    Group list, the entry will bind to.

  • payload (StringIO)

    Raw data.

Returns:



60
61
62
63
64
65
66
67
68
# File 'lib/keepassx/entry.rb', line 60

def self.extract_from_payload(header, groups, payload)
  items = []
  header.entry_number.times do
    entry       = Entry.new(payload)
    entry.group = groups.detect { |g| g.id.eql? entry.group_id }
    items << entry
  end
  items
end

.fieldsArray<Symbol>

Get list of supported entry fields.

Returns:

  • (Array<Symbol>)


74
75
76
# File 'lib/keepassx/entry.rb', line 74

def self.fields
  FIELD_MAPPING.keys
end

Instance Method Details

#group_idObject



123
124
125
# File 'lib/keepassx/entry.rb', line 123

def group_id
  get :groupid
end