ribbon 0.4.3 → 0.4.4
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.rb +18 -18
- data/lib/ribbon/version.rb +1 -1
- data/lib/ribbon/wrapper.rb +9 -0
- metadata +5 -5
data/lib/ribbon.rb
CHANGED
@@ -108,6 +108,23 @@ class Ribbon < BasicObject
|
|
108
108
|
end
|
109
109
|
end
|
110
110
|
|
111
|
+
# Computes a simple key: value string for easy visualization of this ribbon.
|
112
|
+
#
|
113
|
+
# In +opts+ can be specified several options that customize how the string
|
114
|
+
# is generated. Among those options:
|
115
|
+
#
|
116
|
+
# [:separator] Used to separate a key/value pair. Default is <tt>': '</tt>.
|
117
|
+
# [:key] Symbol that will be sent to the key in order to obtain its
|
118
|
+
# string representation. Defaults to <tt>:to_s</tt>.
|
119
|
+
# [:value] Symbol that will be sent to the value in order to obtain its
|
120
|
+
# string representation. Defaults to <tt>:inspect</tt>.
|
121
|
+
def to_s(opts = {})
|
122
|
+
to_s_recursive opts
|
123
|
+
end
|
124
|
+
|
125
|
+
# Same as #to_s.
|
126
|
+
alias inspect to_s
|
127
|
+
|
111
128
|
# If <tt>object</tt> is a hash, converts it to a ribbon. If it is an array,
|
112
129
|
# converts any hashes inside.
|
113
130
|
def self.convert(object)
|
@@ -129,23 +146,6 @@ class Ribbon < BasicObject
|
|
129
146
|
ribbon
|
130
147
|
end
|
131
148
|
|
132
|
-
# Computes a simple key: value string for easy visualization of this ribbon.
|
133
|
-
#
|
134
|
-
# In +opts+ can be specified several options that customize how the string
|
135
|
-
# is generated. Among those options:
|
136
|
-
#
|
137
|
-
# [:separator] Used to separate a key/value pair. Default is <tt>': '</tt>.
|
138
|
-
# [:key] Symbol that will be sent to the key in order to obtain its
|
139
|
-
# string representation. Defaults to <tt>:to_s</tt>.
|
140
|
-
# [:value] Symbol that will be sent to the value in order to obtain its
|
141
|
-
# string representation. Defaults to <tt>:inspect</tt>.
|
142
|
-
def to_s(opts = {})
|
143
|
-
to_s_recursive opts
|
144
|
-
end
|
145
|
-
|
146
|
-
# Same as #to_s.
|
147
|
-
alias inspect to_s
|
148
|
-
|
149
149
|
# Merges the hash of +new+ with the hash of +old+, creating a new ribbon in
|
150
150
|
# the process.
|
151
151
|
def self.merge(old, new, &block)
|
@@ -169,7 +169,7 @@ class Ribbon < BasicObject
|
|
169
169
|
end
|
170
170
|
|
171
171
|
# Wraps a ribbon instance in a Ribbon::Wrapper.
|
172
|
-
def self.wrap(ribbon = Ribbon.new)
|
172
|
+
def self.wrap(ribbon = ::Ribbon.new)
|
173
173
|
::Ribbon::Wrapper.new ribbon
|
174
174
|
end
|
175
175
|
|
data/lib/ribbon/version.rb
CHANGED
data/lib/ribbon/wrapper.rb
CHANGED
@@ -103,6 +103,9 @@ class Ribbon < BasicObject
|
|
103
103
|
# pass it to the Ribbon constructor:
|
104
104
|
#
|
105
105
|
# ribbon = Ribbon.new YAML.load(str)
|
106
|
+
#
|
107
|
+
# Alternatively, you can pass a YAML string to the Wrapper::from_yaml
|
108
|
+
# method.
|
106
109
|
def to_yaml
|
107
110
|
to_hash.to_yaml
|
108
111
|
end
|
@@ -153,5 +156,11 @@ class Ribbon < BasicObject
|
|
153
156
|
ribbon
|
154
157
|
end
|
155
158
|
|
159
|
+
# Deserializes the hash from the +string+ using YAML and uses it to
|
160
|
+
# construct a new wrapped Ribbon.
|
161
|
+
def self.from_yaml(string)
|
162
|
+
::Ribbon::Wrapper.new YAML.load(string)
|
163
|
+
end
|
164
|
+
|
156
165
|
end
|
157
166
|
end
|
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.4.
|
4
|
+
version: 0.4.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-01-03 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rookie
|
16
|
-
requirement: &
|
16
|
+
requirement: &18087600 !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: *18087600
|
25
25
|
description: Ruby Object Notation. Inspired by JSON and OpenStruct.
|
26
26
|
email: matheus.a.m.moreira@gmail.com
|
27
27
|
executables: []
|
@@ -55,7 +55,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
55
55
|
version: '0'
|
56
56
|
segments:
|
57
57
|
- 0
|
58
|
-
hash: -
|
58
|
+
hash: -3618044830386511159
|
59
59
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
60
|
none: false
|
61
61
|
requirements:
|
@@ -64,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
64
64
|
version: '0'
|
65
65
|
segments:
|
66
66
|
- 0
|
67
|
-
hash: -
|
67
|
+
hash: -3618044830386511159
|
68
68
|
requirements: []
|
69
69
|
rubyforge_project:
|
70
70
|
rubygems_version: 1.8.10
|