lib/keepassx/entry.rb in ruby-keepassx-0.2.0beta11 vs lib/keepassx/entry.rb in ruby-keepassx-0.2.0

- old
+ new

@@ -49,10 +49,16 @@ :binary_data => :binary_data, :comment => :notes, } + # Create entries from raw data. + # + # @param header [Keepassx::Header] Keepassx database header. + # @param groups [Array<Keepassx::Group>] Group list, the entry will bind to. + # @param payload [StringIO] Raw data. + # @return [Array<Keepassx::Entry>] 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 } @@ -60,10 +66,13 @@ end items end + # Get list of supported entry fields. + # + # @return [Array<Symbol>] def self.fields FIELD_MAPPING.keys end @@ -76,12 +85,12 @@ 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 } + field_list = FIELD_MAPPING.keys + data = payload.select { |k| field_list.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 @@ -95,9 +104,13 @@ attr_reader :group + # Set parent group. + # + # @param v [Keepassx::Group] Parent group. + # @return [Keepassx::Group] def group= v if v.is_a? Keepassx::Group self.group_id = v.id @group = v else