Class: Crystalball::Prediction

Inherits:
Object
  • Object
show all
Defined in:
lib/crystalball/prediction.rb

Overview

Class for Crystalball prediction results

Instance Method Summary collapse

Constructor Details

#initialize(records) ⇒ Prediction

Returns a new instance of Prediction.



6
7
8
# File 'lib/crystalball/prediction.rb', line 6

def initialize(records)
  @records = records
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args, &block) ⇒ Object



23
24
25
# File 'lib/crystalball/prediction.rb', line 23

def method_missing(*args, &block)
  records.respond_to?(*args) ? records.public_send(*args, &block) : super
end

Instance Method Details

#compactObject

When the records are something like:

./spec/foo ./spec/foo/bar_spec.rb

this returns just ./spec/foo



13
14
15
16
17
# File 'lib/crystalball/prediction.rb', line 13

def compact
  sort_by(&:length).each_with_object([]) do |c, result|
    result << c unless result.any? { |r| c.start_with?(r) }
  end.compact
end

#respond_to_missing?(*args) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/crystalball/prediction.rb', line 27

def respond_to_missing?(*args)
  records.respond_to?(*args)
end

#to_aObject



19
20
21
# File 'lib/crystalball/prediction.rb', line 19

def to_a
  records
end