Class: RubeePass::Group
- Inherits:
-
Object
- Object
- RubeePass::Group
- Includes:
- Comparable
- Defined in:
- lib/rubeepass/group.rb
Instance Attribute Summary collapse
-
#entries ⇒ Object
Returns the value of attribute entries.
-
#group ⇒ Object
Returns the value of attribute group.
-
#groups ⇒ Object
Returns the value of attribute groups.
-
#keepass ⇒ Object
Returns the value of attribute keepass.
-
#name ⇒ Object
Returns the value of attribute name.
-
#path ⇒ Object
Returns the value of attribute path.
-
#uuid ⇒ Object
Returns the value of attribute uuid.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object
- #details(level = 0, show_passwd = false) ⇒ Object
- #entries_by_title(title, case_insensitive = false) ⇒ Object
- #entry_by_uuid(uuid) ⇒ Object
- #entry_titles ⇒ Object
- #find_group(path, case_insensitive = false) ⇒ Object
- #find_group_like(path) ⇒ Object
- #fuzzy_find(search) ⇒ Object
- #group_by_uuid(uuid) ⇒ Object
- #group_names ⇒ Object
- #groups_by_name(name, case_insensitive = false) ⇒ Object
- #has_entry?(entry) ⇒ Boolean
- #has_entry_like?(entry) ⇒ Boolean
- #has_group?(group) ⇒ Boolean
- #has_group_like?(group) ⇒ Boolean
-
#initialize(group, keepass, name, notes, uuid) ⇒ Group
constructor
A new instance of Group.
- #to_s ⇒ Object
Constructor Details
#initialize(group, keepass, name, notes, uuid) ⇒ Group
Returns a new instance of Group.
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/rubeepass/group.rb', line 214 def initialize( group, keepass, name, notes, uuid ) @entries = Hash.new @group = group @groups = Hash.new @keepass = keepass @name = name @notes = notes @uuid = uuid @path = @name @path = "#{@group.path}/#{@name}" if (@group) @path.gsub!(%r{^//}, "/") end |
Instance Attribute Details
#entries ⇒ Object
Returns the value of attribute entries.
7 8 9 |
# File 'lib/rubeepass/group.rb', line 7 def entries @entries end |
#group ⇒ Object
Returns the value of attribute group.
8 9 10 |
# File 'lib/rubeepass/group.rb', line 8 def group @group end |
#groups ⇒ Object
Returns the value of attribute groups.
9 10 11 |
# File 'lib/rubeepass/group.rb', line 9 def groups @groups end |
#keepass ⇒ Object
Returns the value of attribute keepass.
10 11 12 |
# File 'lib/rubeepass/group.rb', line 10 def keepass @keepass end |
#name ⇒ Object
Returns the value of attribute name.
11 12 13 |
# File 'lib/rubeepass/group.rb', line 11 def name @name end |
#path ⇒ Object
Returns the value of attribute path.
12 13 14 |
# File 'lib/rubeepass/group.rb', line 12 def path @path end |
#uuid ⇒ Object
Returns the value of attribute uuid.
13 14 15 |
# File 'lib/rubeepass/group.rb', line 13 def uuid @uuid end |
Class Method Details
.from_xml(keepass, parent, xml) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/rubeepass/group.rb', line 95 def self.from_xml(keepass, parent, xml) name = "/" name = xml.elements["Name"].text || "" if (parent) notes = "" notes = xml.elements["Notes"].text || "" if (parent) uuid = "" uuid = xml.elements["UUID"].text || "" if (parent) group = RubeePass::Group.new( parent, keepass, name, notes, uuid ) if (xml.elements["Entry"]) xml.elements.each("Entry") do |entry_xml| entry = RubeePass::Entry.from_xml( keepass, group, entry_xml ) group.entries[entry.uuid] = entry end end if (xml.elements["Group"]) xml.elements.each("Group") do |group_xml| child = RubeePass::Group.from_xml( keepass, group, group_xml ) group.groups[child.uuid] = child end end return group end |
Instance Method Details
#<=>(other) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/rubeepass/group.rb', line 19 def <=>(other) if (self.name.downcase == other.name.downcase) return (self.uuid <=> other.uuid) end return (self.name.downcase <=> other.name.downcase) end |
#==(other) ⇒ Object
15 16 17 |
# File 'lib/rubeepass/group.rb', line 15 def ==(other) return (self.uuid == other.uuid) end |
#details(level = 0, show_passwd = false) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rubeepass/group.rb', line 26 def details(level = 0, show_passwd = false) out = Array.new lvl = " " * level group_details = [hilight_header(@path)] if (level == 0) group_details = [hilight_header(@name)] if (level != 0) group_details.each do |line| out.push("#{lvl}#{line}") end @groups.values.each do |group| out.push(group.details(level + 1, show_passwd)) end div = "-" * (70 - lvl.length - 2) out.push("#{lvl} #{div}") if (!@entries.empty?) @entries.values.each do |entry| out.push(entry.details(level + 1, show_passwd)) out.push("#{lvl} #{div}") end return out.join("\n") end |
#entries_by_title(title, case_insensitive = false) ⇒ Object
63 64 65 66 67 68 69 70 71 |
# File 'lib/rubeepass/group.rb', line 63 def entries_by_title(title, case_insensitive = false) return @entries.values.select do |entry| (entry.title == title) || ( case_insensitive && (entry.title.downcase == title.downcase) ) end end |
#entry_by_uuid(uuid) ⇒ Object
51 52 53 |
# File 'lib/rubeepass/group.rb', line 51 def entry_by_uuid(uuid) return @entries[uuid] end |
#entry_titles ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/rubeepass/group.rb', line 55 def entry_titles return @entries.values.map do |entry| entry.title end.sort do |a, b| a.downcase <=> b.downcase end end |
#find_group(path, case_insensitive = false) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/rubeepass/group.rb', line 73 def find_group(path, case_insensitive = false) return nil if (@keepass.nil?) path = @keepass.absolute_path(path, @path) cwd = @keepass.db path.split("/").each do |group| next if (group.empty?) if (cwd.has_group_like?(group)) cwd = cwd.groups_by_name(group, case_insensitive)[0] else return nil end end return cwd end |
#find_group_like(path) ⇒ Object
91 92 93 |
# File 'lib/rubeepass/group.rb', line 91 def find_group_like(path) return find_group(path, true) end |
#fuzzy_find(search) ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/rubeepass/group.rb', line 138 def fuzzy_find(search) return [Array.new, Array.new] if (@keepass.nil?) search = @path if (search.nil? || search.empty?) search = @keepass.absolute_path(search, @path) path, _, target = search.rpartition("/") new_cwd = find_group(path) return [Array.new, Array.new] if (new_cwd.nil?) if (new_cwd.has_group_like?(target)) new_cwd = new_cwd.groups_by_name(target, true)[0] target = "" end group_completions = new_cwd.group_names entry_completions = new_cwd.entry_titles if (target.empty?) return [group_completions, entry_completions] end group_completions.keep_if do |group| group.downcase.start_with?(target.downcase) end entry_completions.keep_if do |entry| entry.downcase.start_with?(target.downcase) end return [group_completions, entry_completions] end |
#group_by_uuid(uuid) ⇒ Object
170 171 172 |
# File 'lib/rubeepass/group.rb', line 170 def group_by_uuid(uuid) return @groups[uuid] end |
#group_names ⇒ Object
174 175 176 177 178 179 180 |
# File 'lib/rubeepass/group.rb', line 174 def group_names return @groups.values.map do |group| group.name end.sort do |a, b| a.downcase <=> b.downcase end end |
#groups_by_name(name, case_insensitive = false) ⇒ Object
182 183 184 185 186 187 188 189 190 |
# File 'lib/rubeepass/group.rb', line 182 def groups_by_name(name, case_insensitive = false) return @groups.values.select do |group| (group.name == name) || ( case_insensitive && (group.name.downcase == name.downcase) ) end end |
#has_entry?(entry) ⇒ Boolean
192 193 194 |
# File 'lib/rubeepass/group.rb', line 192 def has_entry?(entry) return !entries_by_title(entry).empty? end |
#has_entry_like?(entry) ⇒ Boolean
196 197 198 |
# File 'lib/rubeepass/group.rb', line 196 def has_entry_like?(entry) return !entries_by_title(entry, true).empty? end |
#has_group?(group) ⇒ Boolean
200 201 202 |
# File 'lib/rubeepass/group.rb', line 200 def has_group?(group) return !groups_by_name(group).empty? end |
#has_group_like?(group) ⇒ Boolean
204 205 206 |
# File 'lib/rubeepass/group.rb', line 204 def has_group_like?(group) return !groups_by_name(group, true).empty? end |
#to_s ⇒ Object
234 235 236 |
# File 'lib/rubeepass/group.rb', line 234 def to_s return details end |