Class: Keepassx::Entry

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(payload_io) ⇒ Entry

Returns a new instance of Entry.



43
44
45
46
47
48
49
50
51
# File 'lib/keepassx/entry.rb', line 43

def initialize(payload_io)
  fields = []
  begin
    field = EntryField.new(payload_io)
    fields << field
  end while not field.terminator?

  @fields = fields
end

Instance Attribute Details

#fieldsObject (readonly)

Returns the value of attribute fields.



41
42
43
# File 'lib/keepassx/entry.rb', line 41

def fields
  @fields
end

Class Method Details

.extract_from_payload(header, payload_io) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/keepassx/entry.rb', line 32

def self.extract_from_payload(header, payload_io)
  groups = []
  header.nentries.times do
    group = Entry.new(payload_io)
    groups << group
  end
  groups
end

Instance Method Details

#group_idObject



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

def group_id
  @fields.detect { |field| field.name == 'groupid' }.data
end

#inspectObject



77
78
79
# File 'lib/keepassx/entry.rb', line 77

def inspect
  "Entry<title=#{title.inspect}, username=[FILTERED], password=[FILTERED], notes=#{notes.inspect}>"
end

#lengthObject



53
54
55
# File 'lib/keepassx/entry.rb', line 53

def length
  @fields.map(&:length).reduce(&:+)
end

#notesObject



57
58
59
# File 'lib/keepassx/entry.rb', line 57

def notes
  @fields.detect { |field| field.name == 'notes' }.data.chomp("\000")
end

#passwordObject



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

def password
  @fields.detect { |field| field.name == 'password' }.data.chomp("\000")
end

#titleObject



65
66
67
# File 'lib/keepassx/entry.rb', line 65

def title
  @fields.detect { |field| field.name == 'title' }.data.chomp("\000")
end

#usernameObject



69
70
71
# File 'lib/keepassx/entry.rb', line 69

def username
  @fields.detect { |field| field.name == 'username' }.data.chomp("\000")
end