immosquare-extensions 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a1d5cf291f00c33bf864785c2bf1b72db5ce0c682292da329aa3bef2cd909df2
4
- data.tar.gz: 0d443a7bdb4304e42c7d065085a2a57c84ca57f6ef16078d6ae318953cd80a42
3
+ metadata.gz: 8344d04cc08c20ab66793e39c6db6ec84cadd1cd042b2a41542ae127994bc855
4
+ data.tar.gz: 2f45a3da92e6b929d649f2753df7298343a748470ee74bb0923bd84ca8b6e59f
5
5
  SHA512:
6
- metadata.gz: 8866d06150921a47bd3b23d3b02f65acb3bc51793f55ff1f0097fe29c969a064ed0f61908b792cd1069366a02c6d3312ca5aecee18ace47321a2f357b964ba92
7
- data.tar.gz: 5ee4d9ef0ecbb4374cd2dab28baa8e22bb9909e45c19499194d34698056f3133de6382c2e095273bc6b6c6c63b7960b185a260ec14de913b0ac6dc94cc4fa2cb
6
+ metadata.gz: f3150e1f7f1eab4c0e31d3887e6017e596813fa563329dbb5fa876ab307420ae320542fee0c85a4f3b0f316ad557eba8ed69221253d1753db09c01704ecc4e92
7
+ data.tar.gz: 298f9e60514c83125f1383c087b151b4d9aec2a8a1210c49f9368afee66d6a0c3e4c7755c085971a6634b76469b9411a419797bfa7667d2e04d49d9fed8ea646
@@ -20,21 +20,6 @@ class Hash
20
20
  cpy
21
21
  end
22
22
 
23
- ##============================================================##
24
- ## Convert all keys of the hash to lowercase.
25
- ## If a value is an array, it recursively processes the
26
- ## nested hash elements.
27
- ##
28
- ## Example:
29
- ## { "A" => { "B" => "value" } }.downcase_key => {"a"=>{"b"=>"value"}}
30
- ##============================================================##
31
- def downcase_key
32
- keys.each do |k|
33
- store(k.downcase, (v = delete(k)).is_a?(Array) ? v.map(&:downcase_key) : v)
34
- end
35
- self
36
- end
37
-
38
23
  ##============================================================##
39
24
  ## Calculate the depth (or level) of nesting within a hash.
40
25
  ##
@@ -42,12 +27,15 @@ class Hash
42
27
  ## {a: {b: {c: 1}}}.depth => 3
43
28
  ##============================================================##
44
29
  def depth
45
- 1 + values.map {|v| v.is_a?(Hash) ? v.depth : 1 }.max
30
+ return 0 unless any?
31
+
32
+ 1 + values.map {|v| v.is_a?(Hash) ? v.depth : 0 }.max
46
33
  end
47
34
 
48
35
  ##============================================================##
49
- ## Sort a hash by its keys. If the recursive flag is true,
36
+ ## Sort a hash by its keys. If the recursive flag is true,
50
37
  ## it will sort nested hashes as well.
38
+ ## case-insensitive comparison and stripping of double quotes.
51
39
  ##
52
40
  ## Reference:
53
41
  ## http://dan.doezema.com/2012/04/recursively-sort-ruby-hash-by-key/
@@ -56,6 +44,7 @@ class Hash
56
44
  ## {b: 1, a: {d: 4, c: 3}}.sort_by_key(true) => {:a=>{:c=>3, :d=>4}, :b=>1}
57
45
  ##============================================================##
58
46
  def sort_by_key(recursive = false, &block)
47
+ block ||= proc {|a, b| a.to_s.downcase.gsub("\"", "") <=> b.to_s.downcase.gsub("\"", "") }
59
48
  keys.sort(&block).each_with_object({}) do |key, seed|
60
49
  seed[key] = self[key]
61
50
  seed[key] = seed[key].sort_by_key(true, &block) if recursive && seed[key].is_a?(Hash)
@@ -63,7 +52,7 @@ class Hash
63
52
  end
64
53
 
65
54
  ##============================================================##
66
- ## Flatten a nested hash into a single-level hash. Nested keys
55
+ ## Flatten a nested hash into a single-level hash. Nested keys
67
56
  ## are represented with dot notation.
68
57
  ##
69
58
  ## Reference:
@@ -78,10 +67,14 @@ class Hash
78
67
  v.flatten_hash.map do |h_k, h_v|
79
68
  h["#{k}.#{h_k}".to_sym] = h_v
80
69
  end
81
- else
70
+ else
82
71
  h[k] = v
83
72
  end
84
- end
73
+ end
85
74
  end
86
75
 
76
+
77
+
78
+
79
+
87
80
  end
@@ -24,7 +24,7 @@ class String
24
24
  end
25
25
 
26
26
  ##============================================================##
27
- ## Provide a custom titleize method to handle strings
27
+ ## Provide a custom titleize method to handle strings
28
28
  ## especially ones with hyphens more appropriately.
29
29
  ## Standard titleize does not preserve hyphens in the desired manner.
30
30
  ##
@@ -40,9 +40,9 @@ class String
40
40
  end
41
41
 
42
42
  ##============================================================##
43
- ## Overriding the standard upcase method to provide a more
43
+ ## Overriding the standard upcase method to provide a more
44
44
  ## comprehensive version that correctly handles Unicode characters.
45
- ##
45
+ ##
46
46
  ## Example:
47
47
  ## "José".upcase => "JOSÉ"
48
48
  ##============================================================##
@@ -1,3 +1,3 @@
1
1
  module ImmosquareExtensions
2
- VERSION = "0.1.0".freeze
2
+ VERSION = "0.1.2".freeze
3
3
  end
@@ -3,5 +3,4 @@ require "immosquare-extensions/hash"
3
3
  require "immosquare-extensions/string"
4
4
 
5
5
  module ImmosquareExentions
6
-
7
- end
6
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: immosquare-extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - IMMO SQUARE
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-09-25 00:00:00.000000000 Z
11
+ date: 2023-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: unicode_utils