export_data 0.1.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86b436786e1d9b8b361706c377c622301a2d08592dc078ffa3466c0636cdb35c
|
4
|
+
data.tar.gz: 75be141bfb3c6bc41cedb5784a08e12169fd5e623a3edecfc0f61423237cad60
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa13331c6cfeb321435b526cb52894bfc695cf2f58bb49025072b59cd33e6b7b96e4c6a1cfea0e8cea09de378df7a72cc146a7a22b060cabe4433a4ddd4442a0
|
7
|
+
data.tar.gz: 200e95402b53ad395af2075cfcffdbd53cf41cc5b724eeb1e9ee57e63e2eb9c39109d30ecddbb0be6858c16d921e065c1e8197606c60a82344a7de5d4bc23ab0
|
data/README.md
CHANGED
@@ -1,34 +1,46 @@
|
|
1
|
-
#
|
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 '
|
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
|
-
|
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
|
|
@@ -38,8 +50,8 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
38
50
|
|
39
51
|
## Contributing
|
40
52
|
|
41
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/ronakabhattrz/
|
53
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ronakabhattrz/export_data. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/ronakabhattrz/export_data/blob/master/CODE_OF_CONDUCT.md).
|
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,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "lib/
|
3
|
+
require_relative "lib/export_data/version"
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "export_data"
|
@@ -10,19 +10,19 @@ Gem::Specification.new do |spec|
|
|
10
10
|
|
11
11
|
spec.summary = "A Data Import/Export Gem for Ruby on Rails"
|
12
12
|
spec.description = "Simplify data import and export tasks in Rails applications."
|
13
|
-
spec.homepage = "https://github.com/ronakabhattrz/
|
13
|
+
spec.homepage = "https://github.com/ronakabhattrz/export_data"
|
14
14
|
spec.license = "MIT"
|
15
15
|
spec.required_ruby_version = ">= 2.6.0"
|
16
16
|
|
17
17
|
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
18
18
|
|
19
19
|
spec.metadata["homepage_uri"] = spec.homepage
|
20
|
-
spec.metadata["source_code_uri"] = "https://github.com/ronakabhattrz/
|
21
|
-
spec.metadata["changelog_uri"] = "https://github.com/ronakabhattrz/
|
20
|
+
spec.metadata["source_code_uri"] = "https://github.com/ronakabhattrz/export_data"
|
21
|
+
spec.metadata["changelog_uri"] = "https://github.com/ronakabhattrz/export_data/blob/main/CHANGELOG.md"
|
22
22
|
|
23
23
|
# Specify which files should be added to the gem when it is released.
|
24
24
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
25
|
-
spec.files = %w[.rspec .rubocop.yml CHANGELOG.md CODE_OF_CONDUCT.md LICENSE.txt README.md Rakefile
|
25
|
+
spec.files = %w[.rspec .rubocop.yml CHANGELOG.md CODE_OF_CONDUCT.md LICENSE.txt README.md Rakefile export_data.gemspec lib/export_data.rb lib/export_data/version.rb sig/export_data.rbs]
|
26
26
|
spec.bindir = "exe"
|
27
27
|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
28
28
|
spec.require_paths = ["lib"]
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "
|
3
|
+
require_relative "export_data/version"
|
4
4
|
|
5
5
|
require "csv"
|
6
6
|
|
@@ -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.
|
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-
|
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:
|
@@ -24,18 +24,18 @@ files:
|
|
24
24
|
- LICENSE.txt
|
25
25
|
- README.md
|
26
26
|
- Rakefile
|
27
|
-
-
|
28
|
-
- lib/
|
29
|
-
- lib/
|
30
|
-
- sig/
|
31
|
-
homepage: https://github.com/ronakabhattrz/
|
27
|
+
- export_data.gemspec
|
28
|
+
- lib/export_data.rb
|
29
|
+
- lib/export_data/version.rb
|
30
|
+
- sig/export_data.rbs
|
31
|
+
homepage: https://github.com/ronakabhattrz/export_data
|
32
32
|
licenses:
|
33
33
|
- MIT
|
34
34
|
metadata:
|
35
35
|
allowed_push_host: https://rubygems.org
|
36
|
-
homepage_uri: https://github.com/ronakabhattrz/
|
37
|
-
source_code_uri: https://github.com/ronakabhattrz/
|
38
|
-
changelog_uri: https://github.com/ronakabhattrz/
|
36
|
+
homepage_uri: https://github.com/ronakabhattrz/export_data
|
37
|
+
source_code_uri: https://github.com/ronakabhattrz/export_data
|
38
|
+
changelog_uri: https://github.com/ronakabhattrz/export_data/blob/main/CHANGELOG.md
|
39
39
|
post_install_message:
|
40
40
|
rdoc_options: []
|
41
41
|
require_paths:
|
File without changes
|