csv_json_converter 0.1.0 → 0.1.1

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: b744b7512b59e69995e34dc5a9f6cdfa37d523e2ae4205dbbb838ecc4c672700
4
- data.tar.gz: c615106e4afc07ceca095a4457b7df8c6e26506afa23408ac7b277599e582253
3
+ metadata.gz: bb1717587cef433b03f7926fe88567ef3fc16b7a1a2a963881cd0750550b7d77
4
+ data.tar.gz: 44169ae334d3df842aa410260e4dcc7880fab765d1d2d84709b78af5e3d28f16
5
5
  SHA512:
6
- metadata.gz: a8988c504375a130e9f7782283a97485e2ac7eec0963d864abe5a2b10fbdf1a8981c0fc2231cb173a04c992b014c3837ab42dc50f8d1bf15bd763f936855d58e
7
- data.tar.gz: 65f0687dd84e10e9423690c71ae7b2f3933d87a676e973513b1f5f1d5dafe95b2f175ffe04f8dd75b809a8bd91b5387d841ca8725cab17b36179f75611f56cc6
6
+ metadata.gz: b8e3ddacda3672913642fed427eb42c3127e5dd0bc6efb5d52e59b03927086b6b3bdba5121a146094bda2a57c779d2907a74542f5cf71d9166a5e3cc6650252e
7
+ data.tar.gz: e9f5be03e570d64b791e4fa756f3da345593206416b1117e8d4c2bf1be76aac93810be35978bfa94752fc71d50f79bcb899258457b2eacb848d691b0a23418c7
data/README.md CHANGED
@@ -1,39 +1,73 @@
1
1
  # CsvJsonConverter
2
2
 
3
- TODO: Delete this and the text below, and describe your gem
3
+ <a name="readme-top"></a>
4
+ # :green_book: Table of Contents
5
+ [![csv_json_ - converter](https://img.shields.io/badge/json__or__ruby__to__-csv-2ea44f)](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: json_or_ruby_to_csv <a name="about-project"></a>
17
+ This gem converts data from a variety of sources into a comma-separated value (CSV) format. The gem can convert arrays of JSON objects, arrays of hashes, arrays of ActionController params, simple hashes, or ActiveRecord relations and objects. The CSV format is a common way to store data in a tabular format. It is often used for data exchange between different applications.
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::Csv.to_json(data_csv)
42
+
43
+ print json_data
44
+ #{ "file": "test18.csv",
45
+ # "text": "CMkABfAGXvmSFV",
46
+ # "number": 9892576,
47
+ # "hex": "jz40cbafbec8d6f92e93d22ea6ef5b"
48
+ #}
49
+ #```
50
+ ```
51
+
52
+ **The output looks like below**
53
+ ```{ "file": "test18.csv",
54
+ "text": "CMkABfAGXvmSFV",
55
+ "number": 9892576,
56
+ "hex": "jz40cbafbec8d6f92e93d22ea6ef5b"
57
+ }
58
+ ```
59
+
60
+ ## :busts_in_silhouette: Authors <a name="authors"></a>
61
+ :bust_in_silhouette: Pablo Zambrano
62
+ - GitHub: [@alexoid1](https://github.com/melashu)
63
+ - Twitter: [@pablo_acz](https://twitter.com/meshu102)
64
+ - LinkedIn: [Pablo Alexis Zambrano](https://www.linkedin.com/in/alexzambranocoral/)
65
+ ## :handshake: Contributing <a name="contributing"></a>
66
+ This repo is open for contributions. Issues, and feature requests are welcome!
67
+ Feel free to check the [issues page.](https://github.com/melashu/csv_json_converter/issues)
68
+ ## :star:️ Show your support <a name="support"></a>
69
+ Give a star if you like this project!
70
+ <p align="right">(<a href="#readme-top">back to top</a>)</p>
4
71
 
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
72
 
7
- ## Installation
8
73
 
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).
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CsvJsonConverter
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
@@ -6,8 +6,8 @@ require_relative "csv_json_converter/version"
6
6
  module CsvJsonConverter
7
7
  class Error < StandardError; end
8
8
  # Your code goes here...
9
- class CsvParse
10
- def self.parse(input, headers, separator=',')
9
+ class Csv
10
+ def self.to_json(input, separator=',')
11
11
  for_csv = CSV.parse(input,:col_sep => separator,headers: true, header_converters: :symbol)
12
12
  # treat first row as headers if the caller didn't provide them
13
13
  arr_to_json = for_csv.map(&:to_h).to_json
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.0
4
+ version: 0.1.1
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-23 00:00:00.000000000 Z
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: