Sha256: 9b29836a04eb002bd5d96fe2dd73cf93e0250f9144f61949124ed559c5bfe2ae

Contents?: true

Size: 746 Bytes

Versions: 70

Compression:

Stored size: 746 Bytes

Contents

# require "eitil_core/mocks/array"

class Array

  def self.mock(n=10, type=Integer, &block)
    
    return Array.new(n,&block) if block_given?
    
    case type.to_s
    
    when 'Integer'
      Array.new(n) {|i| i+1}
    
    when 'Float'
      Array.new(n) {|i| i+1.0}
   
    when 'String'
      words = String.mock(n).split
      Array.new(n) {|i| words[i]}
   
    when 'Time'
      time_now = Time.now
      Array.new(n) {|i| time_now + (i * (60 * 60 * 24)) }
   
    when 'Date'
      date_now = Date.today
      Array.new(n) {|i| date_now + (i * 1) }
   
    else
      Array.new(n) do 
        type.send(:new) rescue
          raise NoNewMethodError, 'Please provide Object that responds to `new` call'
      end
    end

  end

end

Version data entries

70 entries across 70 versions & 1 rubygems

Version Path
eitil-2.0.8 eitil_core/lib/eitil_core/mocks/array.rb
eitil-2.0.7 eitil_core/lib/eitil_core/mocks/array.rb
eitil-2.0.6 eitil_core/lib/eitil_core/mocks/array.rb
eitil-2.0.5 eitil_core/lib/eitil_core/mocks/array.rb
eitil-2.0.4 eitil_core/lib/eitil_core/mocks/array.rb
eitil-2.0.3 eitil_core/lib/eitil_core/mocks/array.rb
eitil-2.0.2 eitil_core/lib/eitil_core/mocks/array.rb
eitil-2.0.1 eitil_core/lib/eitil_core/mocks/array.rb
eitil-2.0.0 eitil_core/lib/eitil_core/mocks/array.rb
eitil-1.4.1 eitil_core/lib/eitil_core/mocks/array.rb
eitil-1.4.0 eitil_core/lib/eitil_core/mocks/array.rb
eitil-1.3.12 eitil_core/lib/eitil_core/mocks/array.rb
eitil-1.3.11 eitil_core/lib/eitil_core/mocks/array.rb
eitil-1.3.10 eitil_core/lib/eitil_core/mocks/array.rb
eitil-1.3.9 eitil_core/lib/eitil_core/mocks/array.rb
eitil-1.3.8 eitil_core/lib/eitil_core/mocks/array.rb
eitil-1.3.7 eitil_core/lib/eitil_core/mocks/array.rb
eitil-1.3.6 eitil_core/lib/eitil_core/mocks/array.rb
eitil-1.3.5 eitil_core/lib/eitil_core/mocks/array.rb
eitil-1.3.4 eitil_core/lib/eitil_core/mocks/array.rb