epitools 0.5.119 → 0.5.121

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: 2512c35335e90e398fa2a8e71f7f5fb070edaf73cf52d53c20b1c2af2be5646f
4
- data.tar.gz: 1db6bbad945aad61174cb71dc2f14e9ed563b048706ec368b83eda1062794294
3
+ metadata.gz: 5c2f1d6b3c8ee2295c5ebc00ac021db858ef79075274903dd60f7ceb57c291f7
4
+ data.tar.gz: 325d6a7e6e46df4d8f013e72d9f72dc3bf3186ab8574a24dc115457c9bf53021
5
5
  SHA512:
6
- metadata.gz: d4a3a513f9f47637632998d2264a34fa935a5082997139f1637ead91c6f78fc1f5b6502690c2f5fe107685beac3e8909c1a62c87dd14f669f317ab7d1eb93234
7
- data.tar.gz: 2944e0d81230264af1762c3a8ff439f949c2d79340f2d184061376dd94f2d63d2561d84c36b48312eb7054ed7193cd063fdf94e14ab10e663b2586192a290336
6
+ metadata.gz: 4355388a72c42c1033f7af17f608e4dda3c9d23333c5c1292bfc1eac7afc90f7b7b4b603689a082f5eb28d3c76f2f3a2c9a930ba92f3232fcaa4e20ba6be1793
7
+ data.tar.gz: 4a0363979ac6ed0b2b6fba7b359e1877942000df1979dd75a58adbaef530a3494fa1c0e41123788daaa8c36a8b168bb57b706f381b51875b2c0997e42ba5bc26
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.119
1
+ 0.5.121
@@ -243,6 +243,16 @@ class Array
243
243
  end
244
244
  end
245
245
 
246
+
247
+ #
248
+ # Convert an Array that contanis Hashes to a new Array that contains OpenStructs
249
+ #
250
+ def to_ostruct
251
+ map do |e|
252
+ e.respond_to?(:to_ostruct) ? e.to_ostruct : e
253
+ end
254
+ end
255
+
246
256
  #
247
257
  # Takes an array of numbers, puts them into equal-sized
248
258
  # buckets, and counts the buckets (aka. A Histogram!)
@@ -366,5 +366,14 @@ class Hash
366
366
  duplicate
367
367
  end
368
368
 
369
+ #
370
+ # Convert this Hash (and all nested Hashes, and all nested Arrays containing Hashes) to OpenStruct(s)
371
+ #
372
+ def to_ostruct
373
+ OpenStruct.new(self.map_values do |v|
374
+ v.respond_to?(:to_ostruct) ? v.to_ostruct : v
375
+ end)
376
+ end
377
+
369
378
  end
370
379
 
@@ -245,6 +245,14 @@ module Kernel
245
245
  out.puts self
246
246
  end
247
247
 
248
+ #
249
+ # Global AwesomePrint method (which triggers the loading of AwesomePrint the first time it's called)
250
+ #
251
+ def ap(object, options={})
252
+ AwesomePrint
253
+ Kernel.ap(object, options)
254
+ end
255
+
248
256
  end
249
257
 
250
258
 
@@ -883,6 +883,30 @@ describe Hash do
883
883
  a.should == b
884
884
  end
885
885
 
886
+ it "to_ostructs" do
887
+ test = {
888
+ a: 1,
889
+ b: 2,
890
+ c: {
891
+ a: 3,
892
+ b: 4,
893
+ c: {
894
+ a: :woot
895
+ }
896
+ },
897
+ d: [
898
+ {a: 5},
899
+ {a: 6},
900
+ ]
901
+ }
902
+
903
+ result = test.to_ostruct
904
+ result.a.should == 1
905
+ result.c.a.should == 3
906
+ result.c.c.a.should == :woot
907
+ result.d.first.a.should == 5
908
+ end
909
+
886
910
  end
887
911
 
888
912
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: epitools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.119
4
+ version: 0.5.121
5
5
  platform: ruby
6
6
  authors:
7
7
  - epitron
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-28 00:00:00.000000000 Z
11
+ date: 2019-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec