Sha256: 5997eff9659498eec5a59dfb44332bb7250f40c435b14b8e39f90f8158803b2d

Contents?: true

Size: 800 Bytes

Versions: 4

Compression:

Stored size: 800 Bytes

Contents

module Libnotify
  class IconFinder
    def initialize(dirs)
      @dirs = dirs
    end

    def icon_path(name)
      list = @dirs.map do |dir|
        glob = File.join(dir, name)
        Dir[glob].map { |fullpath| Icon.new(fullpath) }
      end
      if found = list.flatten.sort.first
        found.to_s
      end
    end

    private

    class Icon
      attr_reader :fullpath

      def initialize(fullpath)
        @fullpath = fullpath
      end

      ICON_REGEX = /(\d+)x\d+/
      def resolution
        @resolution ||= @fullpath[ICON_REGEX, 1].to_i
      end

      def to_s
        fullpath
      end

      def <=>(other)
        result = other.resolution <=> self.resolution
        result = self.fullpath    <=> other.fullpath if result == 0
        result
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
libnotify-0.8.4 lib/libnotify/icon_finder.rb
libnotify-0.8.3 lib/libnotify/icon_finder.rb
libnotify-0.8.2 lib/libnotify/icon_finder.rb
libnotify-0.8.1 lib/libnotify/icon_finder.rb