loquor 0.1.2 → 0.2.0

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: a891916202c44567d39b1b214f39452edd263796
4
- data.tar.gz: 815fbff4daaacbf2dc47e8ed248e6d2978338c68
3
+ metadata.gz: 9f90da533241c34e6048170796622c39625586db
4
+ data.tar.gz: 149b90328f1f832b2e232ffac78cbd061345ce66
5
5
  SHA512:
6
- metadata.gz: 99a10b205e5c4597d6405b29faeb2180a04bb5f59afda111926f73d28070d7f79deed65aef6eb02806c04e277e46146ddd70924c2079881345e5db4ad3d4a692
7
- data.tar.gz: 2890c5bf49c393a1c0b46113c903eface6b5387637f945935b7e739152a745fa5671f17ea8a9a518e698dfd02cb2d2137b5f936729090bc9d72810b80ac1f2f9
6
+ metadata.gz: 3d99385acd26254da7e23c86af5928c62f1d918de78cfe9ebfc2f8df3ad29a24975e3dd3659f1207d1ee542bdc74159872160a42354d128cbe278ecb8cee9606
7
+ data.tar.gz: 3fcdc72de7f80141f9cae06ba6795e589c65405065b3cff52b8f258da54076fa8d22d4d68419d7534b77d71fe3dae7b8ed0e7ab4c58071d4f0eb80d5cd1b7a3c
data/CHANGELOG.md CHANGED
@@ -1,3 +1,5 @@
1
- # 0.1.2 / 2013-11-22
1
+ # 0.2.0 / 2013-11-23
2
+ * [FEATURE] Improve access to keys on Representations
2
3
 
4
+ # 0.1.2 / 2013-11-22
3
5
  * [FEATURE] Responses from JSON now response to dot syntax
data/lib/loquor.rb CHANGED
@@ -17,6 +17,7 @@ module Loquor
17
17
  "GroupDiscussion" => "/group_discussions",
18
18
  "GroupDiscussionPost" => "/group_discussion_posts",
19
19
  "MediaFile" => "/media_files",
20
+ "MeshHeading" => "/mesh_headings",
20
21
  "Mnemonic" => "/mnemonics",
21
22
  "PremiumTutorial" => "/premium_tutorials",
22
23
  "Partner" => "/partners",
@@ -1,4 +1,7 @@
1
1
  module Loquor
2
+ class RepresentationHashKeyMissingError < LoquorError
3
+
4
+ end
2
5
  class Representation
3
6
  def initialize(hash)
4
7
  @hash = hash
@@ -15,14 +18,28 @@ module Loquor
15
18
  end
16
19
 
17
20
  def [](key)
18
- @hash[key]
21
+ fetch_indescriminately(key)
22
+ rescue RepresentationHashKeyMissingError
23
+ nil
19
24
  end
20
25
 
21
26
  def method_missing(name, *args)
27
+ fetch_indescriminately(name, *args)
28
+ rescue RepresentationHashKeyMissingError
29
+ @hash.send(name, *args)
30
+ end
31
+
32
+ private
33
+
34
+ def fetch_indescriminately(name, *args)
22
35
  if @hash.has_key?(name)
23
36
  @hash[name]
37
+ elsif @hash.has_key?(name.to_s)
38
+ @hash[name.to_s]
39
+ elsif @hash.has_key?(name.to_s.to_sym)
40
+ @hash[name.to_s.to_sym]
24
41
  else
25
- super
42
+ raise RepresentationHashKeyMissingError.new
26
43
  end
27
44
  end
28
45
  end
@@ -1,3 +1,3 @@
1
1
  module Loquor
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -7,6 +7,21 @@ module Loquor
7
7
  assert_equal "bar", representation[:foo]
8
8
  end
9
9
 
10
+ def test_hash_symbol_keys_are_accessible_as_strings
11
+ representation = Representation.new({foo: "bar"})
12
+ assert_equal "bar", representation["foo"]
13
+ end
14
+
15
+ def test_hash_string_keys_are_accessible_as_symbols
16
+ representation = Representation.new({"foo" => "bar"})
17
+ assert_equal "bar", representation[:foo]
18
+ end
19
+
20
+ def test_hash_keys_are_accessible_as_orignals
21
+ representation = Representation.new({1 => "bar"})
22
+ assert_equal "bar", representation[1]
23
+ end
24
+
10
25
  def test_hash_keys_are_accessible_via_methods
11
26
  representation = Representation.new({foo: "bar"})
12
27
  assert_equal "bar", representation.foo
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: loquor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Walker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-22 00:00:00.000000000 Z
11
+ date: 2013-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: filum