Class: Keepassx::Entry
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
-
#group ⇒ Object
Returns the value of attribute group.
Class Method Summary collapse
-
.extract_from_payload(header, groups, payload) ⇒ Array<Keepassx::Entry>
Create entries from raw data.
-
.fields ⇒ Array<Symbol>
Get list of supported entry fields.
Instance Method Summary collapse
- #group_id ⇒ Object
-
#initialize(payload) ⇒ Entry
constructor
A new instance of Entry.
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
#group ⇒ Object
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.
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 |
.fields ⇒ Array<Symbol>
Get list of supported entry fields.
74 75 76 |
# File 'lib/keepassx/entry.rb', line 74 def self.fields FIELD_MAPPING.keys end |
Instance Method Details
#group_id ⇒ Object
123 124 125 |
# File 'lib/keepassx/entry.rb', line 123 def group_id get :groupid end |