Class: Keepassx::Group

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

Constant Summary collapse

FIELD_CLASS =
Keepassx::GroupField
FIELD_MAPPING =
{
    :id         => :groupid,
    :title      => :group_name,
    :icon       => :imageid,
    :lastmod    => :lastmod_time,
    :lastaccess => :lastacc_time,
    :creation   => :creation_time,
    :expire     => :expire_time,
    :level      => :level,
    :flags      => :flags
}

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) ⇒ Group

Returns a new instance of Group.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/keepassx/group.rb', line 58

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 "'id' is required" if payload[:id].nil?

    group_parent = payload.delete :parent
    @fields      = []
    default_fields.merge(payload).each do |k, v|
      @fields << self.send("#{k.to_s}=", v)
    end

    self.parent = group_parent

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

Instance Attribute Details

#parentObject

Returns the value of attribute parent.



55
56
57
# File 'lib/keepassx/group.rb', line 55

def parent
  @parent
end

Class Method Details

.extract_from_payload(header, payload_io) ⇒ Object



43
44
45
46
47
# File 'lib/keepassx/group.rb', line 43

def self.extract_from_payload(header, payload_io)
  groups = []
  header.group_number.times { groups << Group.new(payload_io) }
  groups
end

.fieldsObject

return



50
51
52
# File 'lib/keepassx/group.rb', line 50

def self.fields
  FIELD_MAPPING.keys
end

Instance Method Details

#levelObject



107
108
109
110
# File 'lib/keepassx/group.rb', line 107

def level
  value = get :level
  value.nil? ? 0 : value
end