Class: Progress::WithProgress

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

Overview

Handling with_progress

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(enum, title = nil, length = nil) ⇒ WithProgress

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



19
20
21
# File 'lib/progress/with_progress.rb', line 19

def initialize(enum, title = nil, length = nil)
  @enum, @title, @length = enum, title, length
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



45
46
47
48
49
50
51
# File 'lib/progress/with_progress.rb', line 45

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

Instance Attribute Details

#enumObject (readonly) Also known as: enumerable

Returns the value of attribute enum.



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

def enum
  @enum
end

#titleObject (readonly)

Returns the value of attribute title.



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

def title
  @title
end

Class Method Details

.new(*args, &block) ⇒ Object

If block given run each on instance otherwise return instance



13
14
15
# File 'lib/progress/with_progress.rb', line 13

def self.new(*args, &block)
  block ? super.each(&block) : super
end

Instance Method Details

#in_threads(*args, &block) ⇒ Object

befriend with in_threads gem



29
30
31
32
33
# File 'lib/progress/with_progress.rb', line 29

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

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

Returns:

  • (Boolean)


40
41
42
# File 'lib/progress/with_progress.rb', line 40

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

#respond_to_missing?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/progress/with_progress.rb', line 35

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

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

returns self but changes title



24
25
26
# File 'lib/progress/with_progress.rb', line 24

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