ludo-roart 0.1.12 → 0.1.13

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.
@@ -1,15 +1,23 @@
1
1
  class Hash
2
- def to_content_format
3
- fields = self.map do |key,value|
4
- unless value.nil?
5
- value = Roart::ContentFormatter.format_string(value.to_s)
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}: #{value}"
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}: #{value}"
12
+ "#{key.to_s}"
10
13
  else
11
- "#{key.to_s.camelize}: #{value}"
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
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{ludo-roart}
5
- s.version = "0.1.12"
5
+ s.version = "0.1.13"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["PJ Davis"]
@@ -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: 3
4
+ hash: 1
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 12
10
- version: 0.1.12
9
+ - 13
10
+ version: 0.1.13
11
11
  platform: ruby
12
12
  authors:
13
13
  - PJ Davis