ribbon 0.0.2 → 0.0.3
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.
- data/lib/ribbon/object.rb +24 -4
- data/lib/ribbon/version.rb +1 -1
- metadata +3 -3
data/lib/ribbon/object.rb
CHANGED
@@ -4,7 +4,8 @@ module Ribbon
|
|
4
4
|
# method calls. This is done via <tt>method_missing</tt>.
|
5
5
|
#
|
6
6
|
# In order to make room for as many method names as possible, Ribbon::Object
|
7
|
-
# inherits from BasicObject
|
7
|
+
# inherits from BasicObject and implements as many methods as possible at the
|
8
|
+
# class level.
|
8
9
|
class Object < BasicObject
|
9
10
|
|
10
11
|
# The internal Hash.
|
@@ -15,6 +16,7 @@ module Ribbon
|
|
15
16
|
# Merges the internal hash with the given one.
|
16
17
|
def initialize(hash = {}, &block)
|
17
18
|
__hash__.merge! hash, &block
|
19
|
+
::Ribbon::Object.convert_all! self
|
18
20
|
end
|
19
21
|
|
20
22
|
# Gets a value by key.
|
@@ -50,9 +52,16 @@ module Ribbon
|
|
50
52
|
end
|
51
53
|
|
52
54
|
# Computes a simple key:value string for easy visualization.
|
53
|
-
|
54
|
-
|
55
|
-
|
55
|
+
#
|
56
|
+
# If given a block, yields the key and value and the value returned from the
|
57
|
+
# block will be used as the string. The block will also be passed to any
|
58
|
+
# internal Ribbon::Object instances.
|
59
|
+
def to_s(&block)
|
60
|
+
values = __hash__.map do |key, value|
|
61
|
+
value = value.to_s &block if ::Ribbon::Object === value
|
62
|
+
block ? block.call(key, value) : "#{key}:#{value}"
|
63
|
+
end
|
64
|
+
"{ Ribbon #{values.join ', '} }"
|
56
65
|
end
|
57
66
|
|
58
67
|
# Same as #to_s.
|
@@ -68,6 +77,17 @@ module Ribbon
|
|
68
77
|
end
|
69
78
|
end
|
70
79
|
|
80
|
+
# Converts all values in the given ribbon.
|
81
|
+
def self.convert_all!(ribbon)
|
82
|
+
ribbon.__hash__.each do |key, value|
|
83
|
+
ribbon[key] = case value
|
84
|
+
when ::Ribbon::Object then convert_all! value
|
85
|
+
else convert value
|
86
|
+
end
|
87
|
+
end
|
88
|
+
ribbon
|
89
|
+
end
|
90
|
+
|
71
91
|
end
|
72
92
|
|
73
93
|
end
|
data/lib/ribbon/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ribbon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-12-27 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rookie
|
16
|
-
requirement: &
|
16
|
+
requirement: &21805340 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *21805340
|
25
25
|
description: Ruby Object Notation. Inspired by JSON and OpenStruct.
|
26
26
|
email: matheus.a.m.moreira@gmail.com
|
27
27
|
executables: []
|