module Keepassx::Database::Finder

Public Instance Methods

find_entries(opts = {}, &block) click to toggle source

Get all matching entries.

@return [Array<Keepassx::Entry>]

# File lib/keepassx/database/finder.rb, line 37
def find_entries(opts = {}, &block)
  find :entry, opts, &block
end
find_entry(opts = {}, &block) click to toggle source

Get the first matching entry.

@return [Keepassx::Entry]

# File lib/keepassx/database/finder.rb, line 10
def find_entry(opts = {}, &block)
  entries = find_entries(opts, &block)
  filter_list(entries)
end
find_group(opts = {}, &block) click to toggle source

Get the first matching group.

@return [Keepassx::Group]

# File lib/keepassx/database/finder.rb, line 19
def find_group(opts = {}, &block)
  groups = find_groups(opts, &block)
  filter_list(groups)
end
find_groups(opts = {}, &block) click to toggle source

Get all matching groups.

@param opts [Hash] @return [Array<Keepassx::Group>]

# File lib/keepassx/database/finder.rb, line 29
def find_groups(opts = {}, &block)
  find :group, opts, &block
end

Private Instance Methods

filter_list(list) click to toggle source

rubocop:enable Metrics/MethodLength

# File lib/keepassx/database/finder.rb, line 96
def filter_list(list)
  list.empty? ? nil : list.first
end
find(item_type, opts = {}) { |i| ... } click to toggle source

Search for items, using AND statement for the search conditions

@param item_type [Symbol] Can be :entry or :group. @param opts [Hash] Search options. @return [Keepassx::Group, Keepassx::Entry]

# File lib/keepassx/database/finder.rb, line 57
def find(item_type, opts = {})
  item_list = item_type == :entry ? @entries : @groups
  items     = opts.empty? ? item_list : deep_search(item_list, opts)

  return items unless block_given?

  items.each do |i|
    yield i
  end
end