Sha256: a18cc3ac2d475448919d156d3bb39fa73a80a51ec723824eafc1155bc2629eec

Contents?: true

Size: 1.52 KB

Versions: 1

Compression:

Stored size: 1.52 KB

Contents

module Remi
  module DataSource
    module DataStub
      def stub_row_array
        @fields.values.map do |attrib|
          stub_values[attrib[:type]].call
        end
      end

      def empty_stub_df
        self.df = Daru::DataFrame.new([], order: @fields.keys)
      end

      def stub_df
        empty_stub_df
        self.df.add_row(stub_row_array)
      end

      def stub_values
        @stub_values ||= Hash.new(->() { Faker::Hipster.word }).merge({
          string:   ->() { Faker::Hipster.word },
          number:   ->() { Faker::Number.decimal(4,4) },
          float:    ->() { Faker::Number.decimal(2,2) },
          integer:  ->() { Faker::Number.number(4) },
          date:     ->() { Faker::Date.backward(3650) },
          datetime: ->() { Faker::Time.backward(3650) },
          boolean:  ->() { ['T','F'].shuffle.first }
        })
      end
    end


    class CsvFile
      include DataStub
      def stub_tmp_file
        @stub_tmp_file ||= Tempfile.new('stub_tmp_file.csv').path
      end

      def write_stub_tmp_file
        File.open(stub_tmp_file, "wb") do |file|
          file.puts stub_header
          file.puts stub_row_csv
        end

        stub_tmp_file
      end

      def stub_header
        @fields.keys.join(@csv_options[:col_sep])
      end

      def stub_row_csv
        stub_row_array.join(@csv_options[:col_sep])
      end
    end

    class Salesforce
      include DataStub
    end

    class DataFrame
      include DataStub
    end

    class Postgres
      include DataStub
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
remi-0.2.14 lib/remi/cucumber/data_source.rb