gyoku 0.4.5 → 0.4.6

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,3 +1,13 @@
1
+ ## 0.4.6 (2012-06-28)
2
+
3
+ * Fix: [#16](https://github.com/rubiii/gyoku/issues/16) Date objects were mapped like DateTime objects.
4
+
5
+ Gyoku.xml(date: Date.today) # => "<date>2012-06-28</date>"
6
+
7
+ * Fix: Time objects were also mapped like DateTime objects.
8
+
9
+ Gyoku.xml(time: sunday) # => "<time>16:22:33</time>"
10
+
1
11
  ## 0.4.5 (2012-05-28)
2
12
 
3
13
  * Fix: [issue 8](https://github.com/rubiii/gyoku/issues/8) -
@@ -1,5 +1,5 @@
1
1
  module Gyoku
2
2
 
3
- VERSION = "0.4.5"
3
+ VERSION = "0.4.6"
4
4
 
5
5
  end
@@ -5,13 +5,23 @@ module Gyoku
5
5
  module XMLValue
6
6
  class << self
7
7
 
8
- # xs:dateTime format.
8
+ # xs:date format
9
+ XS_DATE_FORMAT = "%Y-%m-%d"
10
+
11
+ # xs:time format
12
+ XS_TIME_FORMAT = "%H:%M:%S"
13
+
14
+ # xs:dateTime format
9
15
  XS_DATETIME_FORMAT = "%Y-%m-%dT%H:%M:%S%Z"
10
16
 
11
17
  # Converts a given +object+ to an XML value.
12
18
  def create(object, escape_xml = true)
13
- if DateTime === object
19
+ if Time === object
20
+ object.strftime XS_TIME_FORMAT
21
+ elsif DateTime === object
14
22
  object.strftime XS_DATETIME_FORMAT
23
+ elsif Date === object
24
+ object.strftime XS_DATE_FORMAT
15
25
  elsif String === object
16
26
  escape_xml ? CGI.escapeHTML(object) : object
17
27
  elsif object.respond_to?(:to_datetime)
@@ -2,13 +2,22 @@ require "spec_helper"
2
2
 
3
3
  describe Gyoku::XMLValue do
4
4
 
5
- let(:datetime) { DateTime.new 2012, 03, 22, 16, 22, 33 }
6
- let(:datetime_string) { "2012-03-22T16:22:33+00:00" }
7
-
8
5
  describe ".create" do
9
6
  context "for DateTime objects" do
10
7
  it "returns an xs:dateTime compliant String" do
11
- create(datetime).should == datetime_string
8
+ create(DateTime.new(2012, 03, 22, 16, 22, 33)).should == "2012-03-22T16:22:33+00:00"
9
+ end
10
+ end
11
+
12
+ context "for Date objects" do
13
+ it "returns an xs:date compliant String" do
14
+ create(Date.new(2012, 03, 22)).should == "2012-03-22"
15
+ end
16
+ end
17
+
18
+ context "for Time objects" do
19
+ it "returns an xs:time compliant String" do
20
+ create(Time.local(2012, 03, 22, 16, 22, 33)).should == "16:22:33"
12
21
  end
13
22
  end
14
23
 
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: 5
4
+ hash: 3
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 5
10
- version: 0.4.5
9
+ - 6
10
+ version: 0.4.6
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: 2012-05-28 00:00:00 Z
18
+ date: 2012-06-28 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  version_requirements: &id001 !ruby/object:Gem::Requirement