Class: Enumark::Dir

Inherits:
Object
  • Object
show all
Defined in:
lib/enumark/dir.rb

Instance Method Summary collapse

Constructor Details

#initialize(dir) ⇒ Dir

Returns a new instance of Dir.



5
6
7
8
# File 'lib/enumark/dir.rb', line 5

def initialize(dir)
  @enumarks = ::Dir.glob(dir).map{ |f| ::Enumark.new(f) }
  raise 'Not enough to process' if @enumarks.count <= 1
end

Instance Method Details

#addedObject



10
11
12
# File 'lib/enumark/dir.rb', line 10

def added
  @added ||= (@enumarks[-1] - @enumarks[-2])
end

#allObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/enumark/dir.rb', line 26

def all
  Enumerator.new do |yielder|
    logger = Config.get(:logger)
    file_count = @enumarks.count

    @enumarks.each_with_index do |enum, idx|
      enum.each do |item|
        yielder << item
        logger.printf("--> %6d/%-6d = %3f \r", idx + 1, file_count, ((idx + 1).to_f / file_count * 100).round(2)) if logger
      end
    end

    logger.puts if logger
  end
end

#deletedObject



14
15
16
# File 'lib/enumark/dir.rb', line 14

def deleted
  @deleted ||= @enumarks[0..-2].reverse_each.reduce(&:|) - @enumarks[-1]
end

#staticObject



22
23
24
# File 'lib/enumark/dir.rb', line 22

def static
  @static ||= @enumarks.reverse_each.reduce(&:&)
end

#uniqObject



18
19
20
# File 'lib/enumark/dir.rb', line 18

def uniq
  @uniq ||= @enumarks.reverse_each.reduce(&:|)
end