csv_json_converter 0.1.0 → 0.1.2
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 +4 -4
- data/README.md +64 -34
- data/lib/csv_json_converter/version.rb +1 -1
- data/lib/csv_json_converter.rb +7 -10
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6228b84cfe7878661d694b60dba84af9d48f55c1a81cd964829d3a8eea78a39c
|
4
|
+
data.tar.gz: ff55c26aa989850f9c1f3d407d434387aabc9d3ba0063d5512e9ade3e1b1c120
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8c640903d18eacdeeb9da4a4dd48bc326f25b66d54049281d57a2a175ac2c1c8ad92746e7ec32cf4e087919f9c741b73876b2665ac1c7606a644098b014e217
|
7
|
+
data.tar.gz: c3cfa34d23a6429d35a3efa2f0ce0f92fa6fcbd0202141e7524396421608d101a0bb635981a1555c237d44c0d4150392aa7670b680d82d74666936cb547c4717
|
data/README.md
CHANGED
@@ -1,39 +1,69 @@
|
|
1
1
|
# CsvJsonConverter
|
2
2
|
|
3
|
-
|
3
|
+
<a name="readme-top"></a>
|
4
|
+
# :green_book: Table of Contents
|
5
|
+
[](https://rubygems.org/gems/csv_json_converter)
|
6
|
+
- [:green_book: Table of Contents](#-table-of-contents)
|
7
|
+
- [:book: csv\_json\_converter ](#-csv_json_converter-)
|
8
|
+
- [Installation ](#installation-)
|
9
|
+
- [Usage](#usage)
|
10
|
+
- [Using to\_json](#csv_to_json)
|
11
|
+
- [Using activerecord\_to\_csv](#using-activerecord_to_csv)
|
12
|
+
- [json\_or\_ruby\_to\_csv usage with rails controller](#json_or_ruby_to_csv-usage-with-rails-controller)
|
13
|
+
- [:busts_in_silhouette: Authors ](#-authors-)
|
14
|
+
- [:handshake: Contributing ](#-contributing-)
|
15
|
+
- [:star:️ Show your support ](#️-show-your-support-)
|
16
|
+
# :book: csv_json_convert <a name="about-project"></a>
|
17
|
+
This gem converts a csv string to json object.
|
18
|
+
## Installation <a name="tech-stack"></a>
|
19
|
+
Add the following code to you Gemfile
|
20
|
+
```
|
21
|
+
gem 'csv_json_converter'
|
22
|
+
```
|
23
|
+
or
|
24
|
+
install the gem on your terminal
|
25
|
+
```
|
26
|
+
gem install csv_json_converter
|
27
|
+
```
|
28
|
+
### Usage
|
29
|
+
`require` this gem on the top of your ruby code.
|
30
|
+
#### Covert csv_to_json
|
31
|
+
If you want to convert `csv string`, to json you can use `to_json` method from `CsvJsonConverter`. Let's see how:-
|
32
|
+
|
33
|
+
<i>For example </i>
|
34
|
+
```ruby
|
35
|
+
|
36
|
+
require 'csv_json_converter'
|
37
|
+
|
38
|
+
data_csv='file;text;number;hex
|
39
|
+
test18.csv;CMkABfAGXvmSFV;9892576;jz40cbafbec8d6f92e93d22ea6ef5b'
|
40
|
+
|
41
|
+
json_data = CsvJsonCoverter.to_json(data_csv)
|
42
|
+
|
43
|
+
print json_data
|
44
|
+
|
45
|
+
```
|
46
|
+
|
47
|
+
**The output looks like below**
|
48
|
+
```
|
49
|
+
{ "file": "test18.csv",
|
50
|
+
"text": "CMkABfAGXvmSFV",
|
51
|
+
"number": 9892576,
|
52
|
+
"hex": "jz40cbafbec8d6f92e93d22ea6ef5b"
|
53
|
+
}
|
54
|
+
```
|
55
|
+
|
56
|
+
## :busts_in_silhouette: Authors <a name="authors"></a>
|
57
|
+
:bust_in_silhouette: Pablo Zambrano
|
58
|
+
- GitHub: [@alexoid1](https://github.com/melashu)
|
59
|
+
- Twitter: [@pablo_acz](https://twitter.com/meshu102)
|
60
|
+
- LinkedIn: [Pablo Alexis Zambrano](https://www.linkedin.com/in/alexzambranocoral/)
|
61
|
+
## :handshake: Contributing <a name="contributing"></a>
|
62
|
+
This repo is open for contributions. Issues, and feature requests are welcome!
|
63
|
+
Feel free to check the [issues page.](https://github.com/melashu/csv_json_converter/issues)
|
64
|
+
## :star:️ Show your support <a name="support"></a>
|
65
|
+
Give a star if you like this project!
|
66
|
+
<p align="right">(<a href="#readme-top">back to top</a>)</p>
|
4
67
|
|
5
|
-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/csv_json_converter`. To experiment with that code, run `bin/console` for an interactive prompt.
|
6
68
|
|
7
|
-
## Installation
|
8
69
|
|
9
|
-
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
|
10
|
-
|
11
|
-
Install the gem and add to the application's Gemfile by executing:
|
12
|
-
|
13
|
-
$ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
|
14
|
-
|
15
|
-
If bundler is not being used to manage dependencies, install the gem by executing:
|
16
|
-
|
17
|
-
$ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
|
18
|
-
|
19
|
-
## Usage
|
20
|
-
|
21
|
-
TODO: Write usage instructions here
|
22
|
-
|
23
|
-
## Development
|
24
|
-
|
25
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
26
|
-
|
27
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
28
|
-
|
29
|
-
## Contributing
|
30
|
-
|
31
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/csv_json_converter. 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/[USERNAME]/csv_json_converter/blob/master/CODE_OF_CONDUCT.md).
|
32
|
-
|
33
|
-
## License
|
34
|
-
|
35
|
-
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
36
|
-
|
37
|
-
## Code of Conduct
|
38
|
-
|
39
|
-
Everyone interacting in the CsvJsonConverter project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/csv_json_converter/blob/master/CODE_OF_CONDUCT.md).
|
data/lib/csv_json_converter.rb
CHANGED
@@ -6,16 +6,13 @@ require_relative "csv_json_converter/version"
|
|
6
6
|
module CsvJsonConverter
|
7
7
|
class Error < StandardError; end
|
8
8
|
# Your code goes here...
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
9
|
+
def self.to_json(input, separator=',')
|
10
|
+
for_csv = CSV.parse(input,:col_sep => separator,headers: true, header_converters: :symbol)
|
11
|
+
# treat first row as headers if the caller didn't provide them
|
12
|
+
arr_to_json = for_csv.map(&:to_h).to_json
|
13
|
+
|
14
|
+
arr_to_json
|
15
|
+
|
16
16
|
|
17
|
-
|
18
|
-
end
|
19
|
-
|
20
17
|
end
|
21
18
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: csv_json_converter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- alexoid1
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-08-
|
11
|
+
date: 2023-08-24 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: This gem transform a csv string in a json string.
|
14
14
|
email:
|