Module: Remi::Testing::DataStub
- Included in:
- DataSource
- Defined in:
- lib/remi/testing/data_stub.rb
Instance Method Summary collapse
- #empty_stub_df ⇒ Object
- #stub_boolean(**attribs) ⇒ Object
- #stub_date(**attribs) ⇒ Object
- #stub_datetime(**attribs) ⇒ Object
- #stub_decimal(**attribs) ⇒ Object
- #stub_df ⇒ Object
- #stub_float(**attribs) ⇒ Object
- #stub_integer(**attribs) ⇒ Object
- #stub_json(**attribs) ⇒ Object
- #stub_row_array ⇒ Object
- #stub_string(**attribs) ⇒ Object
- #stub_values(**attribs) ⇒ Object
Instance Method Details
#empty_stub_df ⇒ Object
10 11 12 |
# File 'lib/remi/testing/data_stub.rb', line 10 def empty_stub_df self.df = Daru::DataFrame.new([], order: fields.keys) end |
#stub_boolean(**attribs) ⇒ Object
58 59 60 |
# File 'lib/remi/testing/data_stub.rb', line 58 def stub_boolean(**attribs) ['T','F'].shuffle.first end |
#stub_date(**attribs) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/remi/testing/data_stub.rb', line 44 def stub_date(**attribs) in_format = attribs[:in_format] result = Faker::Date.backward(3650) result = result.strftime(in_format) if in_format result end |
#stub_datetime(**attribs) ⇒ Object
51 52 53 54 55 56 |
# File 'lib/remi/testing/data_stub.rb', line 51 def stub_datetime(**attribs) in_format = attribs[:in_format] result = Faker::Time.backward(3650) result = result.strftime(in_format) if in_format result end |
#stub_decimal(**attribs) ⇒ Object
36 37 38 |
# File 'lib/remi/testing/data_stub.rb', line 36 def stub_decimal(**attribs) Faker::Number.decimal(attribs[:precision],attribs[:scale]) end |
#stub_df ⇒ Object
14 15 16 17 |
# File 'lib/remi/testing/data_stub.rb', line 14 def stub_df empty_stub_df self.df.add_row(stub_row_array) end |
#stub_float(**attribs) ⇒ Object
32 33 34 |
# File 'lib/remi/testing/data_stub.rb', line 32 def stub_float(**attribs) Faker::Number.decimal(2,3) end |
#stub_integer(**attribs) ⇒ Object
40 41 42 |
# File 'lib/remi/testing/data_stub.rb', line 40 def stub_integer(**attribs) Faker::Number.number(4).to_s end |
#stub_json(**attribs) ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/remi/testing/data_stub.rb', line 62 def stub_json(**attribs) if attribs[:json_array] [ stub_string ] else { Faker::Hipster.words(1, true, true) => stub_string } end.to_json end |
#stub_row_array ⇒ Object
4 5 6 7 8 |
# File 'lib/remi/testing/data_stub.rb', line 4 def stub_row_array fields.values.map do |attribs| stub_values(attribs) end end |
#stub_string(**attribs) ⇒ Object
28 29 30 |
# File 'lib/remi/testing/data_stub.rb', line 28 def stub_string(**attribs) Faker::Hipster.word end |
#stub_values(**attribs) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/remi/testing/data_stub.rb', line 19 def stub_values(**attribs) stub_type = "stub_#{attribs[:type]}".to_sym if respond_to?(stub_type) send(stub_type, attribs) else stub_string(attribs) end end |