export_data 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f01d2609e9edb7ea19da8662ce32a0ee180a2b426bc908d9f0da68f3d7fc4dca
4
- data.tar.gz: 44df34f8a9e2174b5e6cbf4baaefb26184862b3bf70e733877989d519ba3f4f0
3
+ metadata.gz: 86b436786e1d9b8b361706c377c622301a2d08592dc078ffa3466c0636cdb35c
4
+ data.tar.gz: 75be141bfb3c6bc41cedb5784a08e12169fd5e623a3edecfc0f61423237cad60
5
5
  SHA512:
6
- metadata.gz: c535faef54e9a40f90c73ebdf1ecdb2b6c01e19f44d64208f720e0f5be1a6ab7e0c69d2a20637804ac9e8cc8f05cb7394b899f0edbe0d628c64f59c7967e1806
7
- data.tar.gz: 2309ab163abd2b13d222113cca8ad2523452b455cc453d7a36c720cf51f32b49379090eb4abc6e789f29eed52959e302cca3147d6c8cd31fa94fdd26b148152f
6
+ metadata.gz: aa13331c6cfeb321435b526cb52894bfc695cf2f58bb49025072b59cd33e6b7b96e4c6a1cfea0e8cea09de378df7a72cc146a7a22b060cabe4433a4ddd4442a0
7
+ data.tar.gz: 200e95402b53ad395af2075cfcffdbd53cf41cc5b724eeb1e9ee57e63e2eb9c39109d30ecddbb0be6858c16d921e065c1e8197606c60a82344a7de5d4bc23ab0
data/README.md CHANGED
@@ -1,34 +1,46 @@
1
- # DataExport
1
+ # ExportData
2
2
 
3
3
  This gem exports model data into different formats, such as CSV. To achieve so, it uses an export model that handles how the data will be shown
4
4
 
5
5
  ## Installation
6
6
 
7
7
  ```ruby
8
- gem 'export_data', '~> 0.1.0'
8
+ gem 'export_data'
9
9
  ```
10
10
 
11
11
  Then, run `bundle install` to install the gem.
12
12
 
13
13
  ## Usage
14
14
 
15
- To use the DataExport::Exporter class, follow these steps:
15
+ To use the DataExport::Exporter class, follow these steps
16
+
17
+ Assuming you have 50 `User` records in your database and your User model represents these records, you can follow these steps:
18
+
19
+ 1) Open your Rails console:
20
+
21
+ ```ruby
22
+ rails console
23
+ ```
24
+
25
+ 2) Retrieve the user records from your database:
26
+
27
+ ```ruby
28
+ users = User.all
29
+ ```
30
+ - This will fetch all the user records from your User model and store them in the users variable.
31
+
32
+ 3) Specify the file path where the CSV file will be saved:
33
+
34
+ ```ruby
35
+ file_path = 'users.csv'
36
+ ```
37
+
38
+ 4) Call the `DataExport::Exporter.export_to_csv` method to export the user records to the CSV file:
16
39
 
17
40
  ```ruby
18
- require 'export_data'
19
-
20
- # Prepare data
21
- data = [
22
- { id: 1, name: 'John', age: 30 },
23
- { id: 2, name: 'Alice', age: 25 }
24
- ]
25
-
26
- # Create an instance of the exporter
27
- exporter = DataExport::Exporter.new
28
-
29
- # Export data to a CSV file
30
- exporter.export_to_csv(data, 'output.csv')
41
+ DataExport::Exporter.export_to_csv(users, file_path)
31
42
  ```
43
+ - This line exports the user records in the `users` variable to the specified CSV file.
32
44
 
33
45
  ## Development
34
46
 
@@ -42,4 +54,4 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/ronaka
42
54
 
43
55
  ## License
44
56
 
45
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
57
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DataExport
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
data/lib/export_data.rb CHANGED
@@ -45,5 +45,24 @@ module DataExport
45
45
  puts "An error occurred while exporting to CSV: #{e.message}"
46
46
  end
47
47
  end
48
+
49
+ def self.export_to_text(objects, file_path)
50
+ begin
51
+ File.open(file_path, 'w') do |file|
52
+ if objects.empty?
53
+ puts 'No objects to export.' # Or handle this case as needed
54
+ return
55
+ end
56
+
57
+ # Write the object's attribute values as text lines
58
+ objects.each do |obj|
59
+ file.puts(obj.attributes.values.join("\t")) # Use '\t' as a delimiter for tab-separated values
60
+ end
61
+ end
62
+ rescue Errno::ENOENT => e
63
+ puts "An error occurred while exporting to text: #{e.message}"
64
+ end
65
+ end
66
+
48
67
  end
49
68
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: export_data
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - RONAK BHATT
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-09-04 00:00:00.000000000 Z
11
+ date: 2023-09-05 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Simplify data import and export tasks in Rails applications.
14
14
  email: