gyoku 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,7 +15,8 @@ Gem::Specification.new do |s|
15
15
 
16
16
  s.add_dependency "builder", ">= 2.1.2"
17
17
 
18
- s.add_development_dependency "rspec", "2.0.0"
18
+ s.add_development_dependency "rspec", "~> 2.4.0"
19
+ s.add_development_dependency "autotest"
19
20
  s.add_development_dependency "mocha", "~> 0.9.9"
20
21
 
21
22
  s.files = `git ls-files`.split("\n")
@@ -14,14 +14,16 @@ module Gyoku
14
14
  iterate_with_xml hash do |xml, key, attributes|
15
15
  attrs = attributes[key] || {}
16
16
  value = hash[key]
17
+ self_closing = key.to_s[-1, 1] == "/"
17
18
  escape_xml = key.to_s[-1, 1] != "!"
18
19
  key = to_xml_key(key)
19
20
 
20
- case value
21
- when ::Array then xml << Array.to_xml(value, key, escape_xml, attrs)
22
- when ::Hash then xml.tag!(key, attrs) { xml << Hash.to_xml(value) }
23
- when NilClass then xml.tag!(key, "xsi:nil" => "true")
24
- else xml.tag!(key, attrs) { xml << to_xml_value(value, escape_xml) }
21
+ case
22
+ when ::Array === value then xml << Array.to_xml(value, key, escape_xml, attrs)
23
+ when ::Hash === value then xml.tag!(key, attrs) { xml << Hash.to_xml(value) }
24
+ when self_closing then xml.tag!(key, attrs)
25
+ when NilClass === value then xml.tag!(key, "xsi:nil" => "true")
26
+ else xml.tag!(key, attrs) { xml << to_xml_value(value, escape_xml) }
25
27
  end
26
28
  end
27
29
  end
@@ -1,5 +1,5 @@
1
1
  module Gyoku
2
2
 
3
- VERSION = "0.1.1"
3
+ VERSION = "0.2.0"
4
4
 
5
5
  end
@@ -6,16 +6,16 @@ module Gyoku
6
6
  # Converts a given +object+ to an XML key.
7
7
  def to_xml_key(key)
8
8
  case key
9
- when Symbol then chop_exclamation_mark(key.to_s).lower_camelcase
10
- else chop_exclamation_mark(key.to_s)
9
+ when Symbol then chop_special_characters(key.to_s).lower_camelcase
10
+ else chop_special_characters(key.to_s)
11
11
  end
12
12
  end
13
13
 
14
14
  private
15
15
 
16
- # Chops existing exclamation marks from the end of a given +string+.
17
- def chop_exclamation_mark(string)
18
- string[-1, 1] == "!" ? string.chop : string
16
+ # Chops special characters from the end of a given +string+.
17
+ def chop_special_characters(string)
18
+ ["!", "/"].include?(string[-1, 1]) ? string.chop : string
19
19
  end
20
20
 
21
21
  end
@@ -62,6 +62,10 @@ describe Gyoku::Hash do
62
62
  to_xml(:some => nil).should == '<some xsi:nil="true"/>'
63
63
  end
64
64
 
65
+ it "should create self-closing tags for Hash keys ending with a forward slash" do
66
+ to_xml("self-closing/" => nil).should == '<self-closing/>'
67
+ end
68
+
65
69
  it "should call to_s on any other Object" do
66
70
  [666, true, false].each do |object|
67
71
  to_xml(:some => object).should == "<some>#{object}</some>"
@@ -4,12 +4,19 @@ describe Gyoku::XMLKey do
4
4
  include Gyoku::XMLKey
5
5
 
6
6
  describe "#to_xml_key" do
7
- it "removes exclamation marks from the end of a String" do
8
- to_xml_key("value").should == "value"
7
+ it "should remove exclamation marks from the end of a String" do
9
8
  to_xml_key("value!").should == "value"
10
9
  end
11
10
 
12
- it "converts snake_case Symbols to lowerCamelCase Strings" do
11
+ it "should remove forward slashes from the end of a String" do
12
+ to_xml_key("self-closing/").should == "self-closing"
13
+ end
14
+
15
+ it "should not convert snake_case Strings" do
16
+ to_xml_key("lower_camel_case").should == "lower_camel_case"
17
+ end
18
+
19
+ it "should convert snake_case Symbols to lowerCamelCase Strings" do
13
20
  to_xml_key(:lower_camel_case).should == "lowerCamelCase"
14
21
  to_xml_key(:lower_camel_case!).should == "lowerCamelCase"
15
22
  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: 25
5
- prerelease: false
4
+ hash: 23
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 1
10
- version: 0.1.1
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
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: 2010-12-22 00:00:00 +01:00
18
+ date: 2011-01-08 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -40,20 +40,34 @@ dependencies:
40
40
  requirement: &id002 !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
- - - "="
43
+ - - ~>
44
44
  - !ruby/object:Gem::Version
45
- hash: 15
45
+ hash: 31
46
46
  segments:
47
47
  - 2
48
+ - 4
48
49
  - 0
49
- - 0
50
- version: 2.0.0
50
+ version: 2.4.0
51
51
  type: :development
52
52
  version_requirements: *id002
53
53
  - !ruby/object:Gem::Dependency
54
- name: mocha
54
+ name: autotest
55
55
  prerelease: false
56
56
  requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 3
62
+ segments:
63
+ - 0
64
+ version: "0"
65
+ type: :development
66
+ version_requirements: *id003
67
+ - !ruby/object:Gem::Dependency
68
+ name: mocha
69
+ prerelease: false
70
+ requirement: &id004 !ruby/object:Gem::Requirement
57
71
  none: false
58
72
  requirements:
59
73
  - - ~>
@@ -65,7 +79,7 @@ dependencies:
65
79
  - 9
66
80
  version: 0.9.9
67
81
  type: :development
68
- version_requirements: *id003
82
+ version_requirements: *id004
69
83
  description: Gyoku converts Ruby Hashes to XML
70
84
  email: me@rubiii.com
71
85
  executables: []
@@ -81,7 +95,6 @@ files:
81
95
  - LICENSE
82
96
  - README.md
83
97
  - Rakefile
84
- - autotest/discover.rb
85
98
  - gyoku.gemspec
86
99
  - lib/gyoku.rb
87
100
  - lib/gyoku/array.rb
@@ -127,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
127
140
  requirements: []
128
141
 
129
142
  rubyforge_project: gyoku
130
- rubygems_version: 1.3.7
143
+ rubygems_version: 1.4.1
131
144
  signing_key:
132
145
  specification_version: 3
133
146
  summary: Converts Ruby Hashes to XML
@@ -1 +0,0 @@
1
- Autotest.add_discovery { "rspec2" }