colon_rocket 0.0.4 → 0.0.5
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/lib/colon_rocket.rb +14 -20
- 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: 2ecb70c4c2d3a1c3103b9f932f0a6cde1cc7fb3960b4922fef3cd4c7f903789c
|
4
|
+
data.tar.gz: 16fec56eb20c4800fdff6198656dd154e16e6a46fbc98bc21f2a04ecbea98d10
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e61f91c6de80c5f3d9e3ce8186f0d67a4bc782500c26722557706d0c49107a1a003f38fa3c8d7e0ecb204fa3212511b3f4475994d616a5b24b6c53ab025feab1
|
7
|
+
data.tar.gz: dc1d1577bdfbe9179db7c0a6c6c0d0f13a2f8d1d829469c1e607cfa12a661782591a8c739b1f5ba7fe63dcdd73fa35305d126d7aa28e5f258b61c55f59cd7c23
|
data/lib/colon_rocket.rb
CHANGED
@@ -1,29 +1,23 @@
|
|
1
|
+
require 'JSON'
|
1
2
|
class ColonRocket
|
2
3
|
class OverlappingKeysException < StandardError; end
|
3
4
|
|
4
|
-
def self.blastoff(hash
|
5
|
-
|
6
|
-
|
7
|
-
obj[val.first.to_s] = val.last.to_s
|
8
|
-
end.to_s.gsub("\"=>\"", "\": \"")
|
9
|
-
puts json
|
5
|
+
def self.blastoff(hash)
|
6
|
+
detect_collisions(hash.keys)
|
7
|
+
puts (hash.to_json)
|
10
8
|
end
|
11
9
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
def self.handle_collision(val, obj, overwrite_collisions, print_collisions)
|
20
|
-
if overwrite_collisions == false
|
21
|
-
raise OverlappingKeysException, 'Collision detected, identical key found as String and Symbol, example { a: "B", "a" => "NOT B" } Pass in a second argument of true (boolean) to overwrite to the final positional value'
|
22
|
-
elsif print_collisions == true
|
23
|
-
stringified_key = val.first.to_s
|
24
|
-
puts "Collision detected, reassigning \"#{stringified_key}\" from #{obj[stringified_key]} to #{val.last.to_s}"
|
10
|
+
def self.detect_collisions(hash_keys)
|
11
|
+
if hash_keys.length != hash_keys.map(&:to_s).uniq.length
|
12
|
+
duplicate_keys = hash_keys.map.
|
13
|
+
with_object(Hash.new(0)) { |key, obj| obj[key.to_s] += 1 }.
|
14
|
+
select { |key, val| val > 1 }
|
15
|
+
puts "~~~~~duplicate key(s) detected~~~~~: #{duplicate_keys}"
|
16
|
+
true
|
25
17
|
end
|
26
18
|
end
|
27
19
|
|
28
|
-
private_class_method :
|
20
|
+
private_class_method :detect_collisions
|
29
21
|
end
|
22
|
+
|
23
|
+
ColonRocket.blastoff({ a: 1, "a" => { b: 2, "b" => 3 } })
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: colon_rocket
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pizza Steve
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-01-05 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: puts a Ruby Hash to your shell as a valid JSON object (without hash rockets)
|
14
14
|
email: stevepentler@gmail.com
|