Class: Progress::WithProgress

Inherits:
Object
  • Object
show all
Defined in:
lib/progress/with_progress.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(enumerable, title, length = nil, &block) ⇒ WithProgress

initialize with object responding to each, title and optional length if block is provided, it is passed to each



9
10
11
12
# File 'lib/progress/with_progress.rb', line 9

def initialize(enumerable, title, length = nil, &block)
  @enumerable, @title, @length = enumerable, title, length
  each(&block) if block
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/progress/with_progress.rb', line 30

def method_missing(method, *args, &block)
  if enumerable_method?(method)
    run(method, *args, &block)
  else
    super(method, *args, &block)
  end
end

Instance Attribute Details

#enumerableObject (readonly)

Returns the value of attribute enumerable.



5
6
7
# File 'lib/progress/with_progress.rb', line 5

def enumerable
  @enumerable
end

#titleObject (readonly)

Returns the value of attribute title.



5
6
7
# File 'lib/progress/with_progress.rb', line 5

def title
  @title
end

Instance Method Details

#in_threads(*args, &block) ⇒ Object

befriend with in_threads gem



20
21
22
23
24
# File 'lib/progress/with_progress.rb', line 20

def in_threads(*args, &block)
  @enumerable.in_threads(*args).with_progress(@title, @length, &block)
rescue
  super
end

#respond_to?(sym, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/progress/with_progress.rb', line 26

def respond_to?(sym, include_private = false)
  enumerable_method?(method) || super(sym, include_private)
end

#with_progress(title = nil, length = nil, &block) ⇒ Object

returns self but changes title



15
16
17
# File 'lib/progress/with_progress.rb', line 15

def with_progress(title = nil, length = nil, &block)
  self.class.new(@enumerable, title, length || @length, &block)
end