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 +4 -4
- data/CHANGELOG.md +3 -1
- data/lib/loquor.rb +1 -0
- data/lib/loquor/representation.rb +19 -2
- data/lib/loquor/version.rb +1 -1
- data/test/representation_test.rb +15 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f90da533241c34e6048170796622c39625586db
|
4
|
+
data.tar.gz: 149b90328f1f832b2e232ffac78cbd061345ce66
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d99385acd26254da7e23c86af5928c62f1d918de78cfe9ebfc2f8df3ad29a24975e3dd3659f1207d1ee542bdc74159872160a42354d128cbe278ecb8cee9606
|
7
|
+
data.tar.gz: 3fcdc72de7f80141f9cae06ba6795e589c65405065b3cff52b8f258da54076fa8d22d4d68419d7534b77d71fe3dae7b8ed0e7ab4c58071d4f0eb80d5cd1b7a3c
|
data/CHANGELOG.md
CHANGED
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
|
-
|
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
|
-
|
42
|
+
raise RepresentationHashKeyMissingError.new
|
26
43
|
end
|
27
44
|
end
|
28
45
|
end
|
data/lib/loquor/version.rb
CHANGED
data/test/representation_test.rb
CHANGED
@@ -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.
|
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-
|
11
|
+
date: 2013-11-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: filum
|