gyoku 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -23,13 +23,18 @@ As you might notice, Gyoku follows a couple of conventions for translating Hashe
23
23
  Conventions
24
24
  -----------
25
25
 
26
- * Hash key Symbols are converted to lowerCamelCase Strings
27
- * Hash key Strings are not converted and may contain namespaces
28
- * Hash keys ending with a forward slash create self-closing tags
29
- * DateTime values are converted to xs:dateTime Strings
26
+ ### Hash keys
27
+
28
+ * Symbols are converted to lowerCamelCase Strings
29
+ * Strings are not converted and may contain namespaces
30
+
31
+ ### Hash values
32
+
33
+ * DateTime objects are converted to xs:dateTime Strings
30
34
  * Objects responding to :to_datetime (except Strings) are converted to xs:dateTime Strings
31
35
  * TrueClass and FalseClass objects are converted to "true" and "false" Strings
32
36
  * NilClass objects are converted to xsi:nil tags
37
+ * These conventions are also applied to the return value of objects responding to :call
33
38
  * All other objects are converted to Strings using :to_s
34
39
 
35
40
  Special characters
@@ -40,6 +45,14 @@ Gyoku escapes special characters unless the Hash key ends with an exclamation ma
40
45
  Gyoku.xml :escaped => "<tag />", :not_escaped! => "<tag />"
41
46
  # => "<escaped>&lt;tag /&gt;</escaped><notEscaped><tag /></notEscaped>"
42
47
 
48
+ Self-closing tags
49
+ -----------------
50
+
51
+ Hash Keys ending with a forward slash create self-closing tags:
52
+
53
+ Gyoku.xml :"self_closing/" => "", "selfClosing/" => nil
54
+ # => "<selfClosing/><selfClosing/>"
55
+
43
56
  Sort XML tags
44
57
  -------------
45
58
 
@@ -1,5 +1,5 @@
1
1
  module Gyoku
2
2
 
3
- VERSION = "0.3.0"
3
+ VERSION = "0.3.1"
4
4
 
5
5
  end
@@ -14,6 +14,8 @@ module Gyoku
14
14
  escape_xml ? CGI.escapeHTML(object) : object
15
15
  elsif object.respond_to?(:to_datetime)
16
16
  to_xml_value object.to_datetime
17
+ elsif object.respond_to?(:call)
18
+ to_xml_value object.call
17
19
  else
18
20
  object.to_s
19
21
  end
@@ -24,16 +24,21 @@ describe Gyoku::XMLValue do
24
24
  to_xml_value("<tag>", false).should == "<tag>"
25
25
  end
26
26
 
27
- it "returns an xs:dateTime compliant String for Objects responding to :to_datetime" do
27
+ it "should return an xs:dateTime compliant String for Objects responding to #to_datetime" do
28
28
  singleton = Object.new
29
29
  def singleton.to_datetime
30
- DateTime.new(2012, 03, 22, 16, 22, 33)
30
+ DateTime.new 2012, 03, 22, 16, 22, 33
31
31
  end
32
32
 
33
33
  to_xml_value(singleton).should == "2012-03-22T16:22:33+00:00"
34
34
  end
35
35
 
36
- it "calls to_s unless the Object responds to to_datetime" do
36
+ it "should #call Proc objects and convert their return value" do
37
+ object = lambda { DateTime.new 2012, 03, 22, 16, 22, 33 }
38
+ to_xml_value(object).should == "2012-03-22T16:22:33+00:00"
39
+ end
40
+
41
+ it "should call #to_s unless the Object responds to #to_datetime" do
37
42
  to_xml_value("value").should == "value"
38
43
  end
39
44
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gyoku
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 0
10
- version: 0.3.0
9
+ - 1
10
+ version: 0.3.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Daniel Harrington
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-23 00:00:00 +01:00
18
+ date: 2011-01-26 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency