recursive_case_indifferent_ostruct 0.1 → 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
  SHA1:
3
- metadata.gz: b398b7f98e4169257f4811888715dd82fd43b4b2
4
- data.tar.gz: f44fee346580aec8bc67449f40223967852f3bc6
3
+ metadata.gz: f29ef3fcb8655257fc1562d6bf09f61be465b3a9
4
+ data.tar.gz: 46487154c944ea8af316dfad6db57ec28f5fe82f
5
5
  SHA512:
6
- metadata.gz: e23e8daeca037f194a719201a486c509462c0e0abaa5bb52f8eb8e392075e885b96e2229195860b1bfc63338ff44202124cab26d8cc2d232bb4f1255cca5c399
7
- data.tar.gz: fde5b277fe47328995e2f6d762f2ea14c11ed1bb41f1b63566807b032541d16673c454737140c1a088773397b527bccf98c65b764aa54221882f5a28433ddc7e
6
+ metadata.gz: 86b4fc3a58b06dbc6b663b95180af5cba20c0db15f10d74659cc081ce3a2edcd7fff9267c8aa587287bfb53669ff883c9293e6d229b21b89b99424d3f876f416
7
+ data.tar.gz: 8fa6ec8cb3e36ff33cd60e8b78096f559a55738ead20cbeb74b4f26a5b454a564983e8e2bb9f3e9643ab05caf83d8446171c3235da6b7500073f2ed0b76c893d
data/README.md CHANGED
@@ -36,7 +36,7 @@ user.last_name # "Johnson"
36
36
  user.father.age # 72
37
37
  user.siblings[0].age # 12
38
38
 
39
- user.birth_place = "New York" # set fields
39
+ user.birth_place = "New York" # sets Birth-Place
40
40
  user.first_name = "Ken" # sets {"firstName" => "Ken", "first-name" => "Ken"}
41
41
  user.mothers_maiden = "Woods" # Since case is mixed in that hash, use default :lower_camel
42
42
 
@@ -44,7 +44,7 @@ user.mothers_maiden = "Woods" # Since case is mixed in that hash, use default :l
44
44
  user.to_h
45
45
  # {
46
46
  # "firstName" => "Ken",
47
- # "first-name" => "Bobby",
47
+ # "first-name" => "Ken",
48
48
  # "LAST_NAME" => "Johnson",
49
49
  # "Birth-Place" => "New York",
50
50
  # "father" => {
@@ -58,6 +58,18 @@ user.to_h
58
58
  ```
59
59
 
60
60
 
61
+ ```
62
+ # .merge() is case insensative
63
+ user = RecursiveCaseIndifferentOstruct.new(first_name: "Bob")
64
+ new_user = user.merge({"FirstName" => "Bobby"})
65
+ new_user.first_name # Bobby
66
+ user.first_name # Bob
67
+
68
+ user.merge!({"FirstName" => "Bobby"})
69
+ user.first_name # Bobby
70
+
71
+ ```
72
+
61
73
  ### Case Matching
62
74
  Since the key matching is fuzzy, should there be two attributes with
63
75
  the same name but different case (`first-name` and `firstName`), the
@@ -89,6 +101,7 @@ The value can still be accessed via `json.pi_value`.
89
101
  if the method is not defined and there is not attribute matching that
90
102
  name. However, all the hash methods operate on the original hash, so
91
103
  `#has_key?`, `#each`, `#fetch`, etc, will not be case-indifferent.
104
+ Feel free to implement them and submit a PR.
92
105
 
93
106
  ```ruby
94
107
  json = RecursiveCaseIndifferentOstruct.new({
@@ -19,6 +19,20 @@ class RecursiveCaseIndifferentOstruct
19
19
  def []=(key, value)
20
20
  handle_assignment(key, value, true)
21
21
  end
22
+
23
+ def merge(other_hash)
24
+ out = self.dup
25
+ other_hash.each do |k, v|
26
+ out.send("#{k}=", v)
27
+ end
28
+ out
29
+ end
30
+
31
+ def merge!(other_hash)
32
+ other_hash.each do |k, v|
33
+ send("#{k}=", v)
34
+ end
35
+ end
22
36
 
23
37
  def method_missing(method_sym, *args, &block)
24
38
  method_name = method_sym.to_s
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: recursive_case_indifferent_ostruct
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Roberts
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-15 00:00:00.000000000 Z
11
+ date: 2016-03-23 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: See github.
14
14
  email: code@polar-concepts.com
@@ -38,7 +38,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
38
38
  version: '0'
39
39
  requirements: []
40
40
  rubyforge_project:
41
- rubygems_version: 2.4.5
41
+ rubygems_version: 2.5.1
42
42
  signing_key:
43
43
  specification_version: 4
44
44
  summary: Access JSON or Hashes attributes without regards to snake_case, camelCase,