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.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object
- #details(level = 0) ⇒ Object
- #entry_titles ⇒ Object
- #find_group(path) ⇒ Object
- #fuzzy_find(input) ⇒ Object
- #group_names ⇒ Object
- #has_entry?(title) ⇒ Boolean
- #has_group?(name) ⇒ Boolean
-
#initialize(params) ⇒ Group
constructor
A new instance of Group.
- #to_s ⇒ Object
Constructor Details
#initialize(params) ⇒ Group
Returns a new instance of Group.
117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/rubeepass/group.rb', line 117 def initialize(params) @entries = Hash.new @group = params.fetch("Group", nil) @groups = Hash.new @keepass = params.fetch("Keepass", nil) @name = params.fetch("Name", "") @uuid = params.fetch("UUID", "") @path = @name @path = "#{@group.path}/#{@name}" if (@group) @path.gsub!(%r{^//}, "/") end |
Instance Attribute Details
#entries ⇒ Object
Returns the value of attribute entries.
6 7 8 |
# File 'lib/rubeepass/group.rb', line 6 def entries @entries end |
#group ⇒ Object
Returns the value of attribute group.
7 8 9 |
# File 'lib/rubeepass/group.rb', line 7 def group @group end |
#groups ⇒ Object
Returns the value of attribute groups.
8 9 10 |
# File 'lib/rubeepass/group.rb', line 8 def groups @groups end |
#keepass ⇒ Object
Returns the value of attribute keepass.
9 10 11 |
# File 'lib/rubeepass/group.rb', line 9 def keepass @keepass end |
#name ⇒ Object
Returns the value of attribute name.
10 11 12 |
# File 'lib/rubeepass/group.rb', line 10 def name @name end |
#path ⇒ Object
Returns the value of attribute path.
11 12 13 |
# File 'lib/rubeepass/group.rb', line 11 def path @path end |
#uuid ⇒ Object
Returns the value of attribute uuid.
12 13 14 |
# File 'lib/rubeepass/group.rb', line 12 def uuid @uuid end |
Instance Method Details
#<=>(other) ⇒ Object
18 19 20 |
# File 'lib/rubeepass/group.rb', line 18 def <=>(other) return (self.name.downcase <=> other.name.downcase) end |
#==(other) ⇒ Object
14 15 16 |
# File 'lib/rubeepass/group.rb', line 14 def ==(other) return (self.uuid == other.uuid) end |
#details(level = 0) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/rubeepass/group.rb', line 22 def details(level = 0) out = Array.new lvl = Array.new(level, " ").join group_details = [ "#{@name}".blue ] group_details[0] = "#{@path}".blue if (level == 0) group_details.each do |line| out.push("#{lvl}#{line}") end @groups.values.each do |group| out.push(group.details(level + 1)) end @entries.values.each do |entry| out.push(entry.details(level + 1)) end return out.join("\n") end |
#entry_titles ⇒ Object
44 45 46 |
# File 'lib/rubeepass/group.rb', line 44 def entry_titles return @entries.keys.sort end |
#find_group(path) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/rubeepass/group.rb', line 48 def find_group(path) 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?(group)) cwd = cwd.groups[group] else return nil end end return cwd end |
#fuzzy_find(input) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/rubeepass/group.rb', line 66 def fuzzy_find(input) return [ [], [], [] ] if (@keepass.nil?) input = @path if (input.nil? || input.empty?) input = @keepass.absolute_path(input, @path) path, target = input.rsplit("/") new_cwd = find_group(path) return [ input, [], [] ] if (new_cwd.nil?) if (new_cwd.has_group?(target)) new_cwd = new_cwd.groups[target] target = "" input += "/" end group_completions = new_cwd.group_names entry_completions = new_cwd.entry_titles if (target.empty?) return [ input, group_completions, entry_completions ] end group_completions.delete_if do |group| !group.downcase.start_with?(target.downcase) end entry_completions.delete_if do |entry| !entry.downcase.start_with?(target.downcase) end return [ input, group_completions, entry_completions ] end |
#group_names ⇒ Object
99 100 101 |
# File 'lib/rubeepass/group.rb', line 99 def group_names return @groups.keys.sort end |
#has_entry?(title) ⇒ Boolean
103 104 105 106 107 108 |
# File 'lib/rubeepass/group.rb', line 103 def has_entry?(title) entry_titles.each do |entry| return true if (title.downcase == entry.downcase) end return false end |
#has_group?(name) ⇒ Boolean
110 111 112 113 114 115 |
# File 'lib/rubeepass/group.rb', line 110 def has_group?(name) group_names.each do |group| return true if (name.downcase == group.downcase) end return false end |
#to_s ⇒ Object
130 131 132 |
# File 'lib/rubeepass/group.rb', line 130 def to_s return details end |