ludo-roart 0.1.12 → 0.1.13
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/roart/core/hash.rb +15 -7
- data/roart.gemspec +1 -1
- data/spec/roart/core/hash_spec.rb +5 -0
- metadata +3 -3
data/lib/roart/core/hash.rb
CHANGED
@@ -1,15 +1,23 @@
|
|
1
1
|
class Hash
|
2
|
-
|
3
|
-
fields =
|
4
|
-
|
5
|
-
|
2
|
+
def to_content_format
|
3
|
+
fields = []
|
4
|
+
|
5
|
+
self.each do |key, values|
|
6
|
+
next if values.nil?
|
7
|
+
|
8
|
+
key_name =
|
6
9
|
if key.to_s.match(/^cf_.+/)
|
7
|
-
"CF-#{key.to_s[3..key.to_s.length].gsub(/_/, " ").camelize.humanize}
|
10
|
+
"CF-#{key.to_s[3..key.to_s.length].gsub(/_/, " ").camelize.humanize}"
|
8
11
|
elsif key.to_s.match(/^CF-.+/)
|
9
|
-
"#{key.to_s}
|
12
|
+
"#{key.to_s}"
|
10
13
|
else
|
11
|
-
"#{key.to_s.camelize}
|
14
|
+
"#{key.to_s.camelize}"
|
12
15
|
end
|
16
|
+
|
17
|
+
values = [values] unless values.is_a?(Array)
|
18
|
+
values.each do |value|
|
19
|
+
value = Roart::ContentFormatter.format_string(value.to_s)
|
20
|
+
fields << "#{key_name}: #{value}"
|
13
21
|
end
|
14
22
|
end
|
15
23
|
content = fields.compact.sort.join("\n")
|
data/roart.gemspec
CHANGED
@@ -24,4 +24,9 @@ describe 'hash extentions' do
|
|
24
24
|
payload.to_content_format
|
25
25
|
end
|
26
26
|
|
27
|
+
it "should return sorted data with the same key multiple times when value is array" do
|
28
|
+
payload = { 'CF-My Day' => %w(Tue Wed Fri), 'CF-My Time' => %w(morning evening) }
|
29
|
+
payload.to_content_format.should == "CF-My Day: Fri\nCF-My Day: Tue\nCF-My Day: Wed\nCF-My Time: evening\nCF-My Time: morning"
|
30
|
+
end
|
31
|
+
|
27
32
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ludo-roart
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 1
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 13
|
10
|
+
version: 0.1.13
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- PJ Davis
|