csv_json_converter 0.1.2 → 0.1.4

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: 6228b84cfe7878661d694b60dba84af9d48f55c1a81cd964829d3a8eea78a39c
4
- data.tar.gz: ff55c26aa989850f9c1f3d407d434387aabc9d3ba0063d5512e9ade3e1b1c120
3
+ metadata.gz: f1f3376d08cdd35e377a8948b5557767c12ecaa6ebb016b211e12d8c13836d8d
4
+ data.tar.gz: 1f48a73d83e9c365b24ea62f640a9b31690c25ed7aa6e7c8e9d01f9f72992031
5
5
  SHA512:
6
- metadata.gz: c8c640903d18eacdeeb9da4a4dd48bc326f25b66d54049281d57a2a175ac2c1c8ad92746e7ec32cf4e087919f9c741b73876b2665ac1c7606a644098b014e217
7
- data.tar.gz: c3cfa34d23a6429d35a3efa2f0ce0f92fa6fcbd0202141e7524396421608d101a0bb635981a1555c237d44c0d4150392aa7670b680d82d74666936cb547c4717
6
+ metadata.gz: f78b16b10cbc8e594395402d2ce6d3cd8f1041f2e2a689664a644defc62ff4ab8ef7045d82eccd23bac63571ab45b3fc3cbb709d5efebf0a1d18738dde061467
7
+ data.tar.gz: 6938447a517037a4d10fc481f8073efadd1a2cb9aa971207b9edc349dd94c24faf6cf38ae0e1d9dca3bcaf2f5acf0f3b3f88b2a589436a61d522a52ccee00db9
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  <a name="readme-top"></a>
4
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)
5
+ [![csv_json_ - converter](https://img.shields.io/badge/csv_json_convert_-csv-2ea44f)](https://rubygems.org/gems/csv_json_converter)
6
6
  - [:green_book: Table of Contents](#-table-of-contents)
7
7
  - [:book: csv\_json\_converter ](#-csv_json_converter-)
8
8
  - [Installation ](#installation-)
@@ -27,7 +27,7 @@ gem install csv_json_converter
27
27
  ```
28
28
  ### Usage
29
29
  `require` this gem on the top of your ruby code.
30
- #### Covert csv_to_json
30
+ ### Covert csv to json
31
31
  If you want to convert `csv string`, to json you can use `to_json` method from `CsvJsonConverter`. Let's see how:-
32
32
 
33
33
  <i>For example </i>
@@ -52,7 +52,30 @@ If you want to convert `csv string`, to json you can use `to_json` method from `
52
52
  "hex": "jz40cbafbec8d6f92e93d22ea6ef5b"
53
53
  }
54
54
  ```
55
+ ### Covert json to csv
56
+ If you want to convert `json object`, to json you can use `to_csv` method from `CsvJsonConverter`. Let's see how:-
55
57
 
58
+ <i>For example </i>
59
+ ```ruby
60
+
61
+ require 'csv_json_converter'
62
+
63
+ data_json={ "file": "test18.csv",
64
+ "text": "CMkABfAGXvmSFV",
65
+ "number": 9892576,
66
+ "hex": "jz40cbafbec8d6f92e93d22ea6ef5b"
67
+ }
68
+
69
+ csv_data = CsvJsonCoverter.to_csv(data_json)
70
+
71
+ print csv_data
72
+
73
+ ```
74
+
75
+ **The output looks like below**
76
+ ```
77
+ "file,text,number,hex\ntest18.csv,CMkABfAGXvmSFV,9892576,jz40cbafbec8d6f92e93d22ea6ef5b
78
+ ```
56
79
  ## :busts_in_silhouette: Authors <a name="authors"></a>
57
80
  :bust_in_silhouette: Pablo Zambrano
58
81
  - GitHub: [@alexoid1](https://github.com/melashu)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CsvJsonConverter
4
- VERSION = "0.1.2"
4
+ VERSION = "0.1.4"
5
5
  end
@@ -15,4 +15,35 @@ module CsvJsonConverter
15
15
 
16
16
 
17
17
  end
18
+
19
+ def self.to_csv(input)
20
+
21
+ for_json=JSON.parse(input)
22
+ column_names = for_json.first.keys
23
+ csv_string=CSV.generate do |csv|
24
+ csv << column_names
25
+ for_json.each do |x|
26
+ csv << x.values
27
+ end
28
+ end
29
+
30
+ csv_string
31
+
32
+ end
18
33
  end
34
+
35
+
36
+ p arr_json=CsvJsonConverter.to_json('file,text,number,hex
37
+ test18.csv,CMkABfAGXvmSFV,9892576,jz40cbafbec8d6f92e93d22ea6ef5b
38
+ test18.csv,NCVTagVs,815097234,jz0ee6f01d178831228b957376f15c
39
+ test18.csv,RCZgwkLosc,3,jz22ff45479c30a890925d5832c319
40
+ test18.csv,HZgYgaBNZFXyVdzuRuddpg,31,jz737707427673939e4c198598cefc
41
+ test18.csv,tfp,6,jzedd110611f58b53215dd0b27f7ba
42
+ ')
43
+
44
+ arr_csv=CsvJsonConverter.to_csv(
45
+ arr_json
46
+ )
47
+
48
+ p arr_csv
49
+
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.2
4
+ version: 0.1.4
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-24 00:00:00.000000000 Z
11
+ date: 2023-08-25 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: This gem transform a csv string in a json string.
14
14
  email:
@@ -27,11 +27,12 @@ files:
27
27
  - lib/csv_json_converter.rb
28
28
  - lib/csv_json_converter/version.rb
29
29
  - sig/csv_json_converter.rbs
30
- homepage: https://github.com/Alexoid1/csv_json_converter
30
+ homepage: https://rubygems.org/gems/csv_json_converter
31
31
  licenses:
32
32
  - MIT
33
33
  metadata:
34
- homepage_uri: https://github.com/Alexoid1/csv_json_converter
34
+ homepage_uri: https://rubygems.org/gems/csv_json_converter
35
+ documentation_uri: https://github.com/Alexoid1/csv_json_converter
35
36
  source_code_uri: https://github.com/Alexoid1/csv_json_converter
36
37
  post_install_message:
37
38
  rdoc_options: []