xml_schema 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog ADDED
@@ -0,0 +1,5 @@
1
+ xml_schema (0.1.0)
2
+
3
+ * XmlSchema.datatype_of returns URI, not String
4
+ * XmlSchema.to_s returns the URI string without trailing "#"
5
+ * XmlSchema.uri (and "[]" accessor, e.g. NS::OWL["hello"]) return an instance of URI
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2012 Slava Kravchenko
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc CHANGED
@@ -6,18 +6,18 @@ XmlSchema gem is a simple convertor utility for XML Schema (literal) datatypes t
6
6
 
7
7
  $ require "xml_schema"
8
8
 
9
- $ XmlSchema.datatype_of(true) # => "http://www.w3.org/2001/XMLSchema#boolean"
10
- $ XmlSchema.datatype_of(Time.now) # => "http://www.w3.org/2001/XMLSchema#time"
9
+ $ XmlSchema.datatype_of(true) # => #<URI::HTTP:0x00000000dcff78 URL:http://www.w3.org/2001/XMLSchema#boolean>
10
+ $ XmlSchema.datatype_of(Time.now) # => #<URI::HTTP:0x00000000dcff78 URL:http://www.w3.org/2001/XMLSchema#time>
11
11
 
12
12
  $ XmlSchema.instantiate("55^^<http://www.w3.org/2001/XMLSchema#int>") # => 55
13
13
 
14
14
  XmlSchema also provides means to access and work with frequently used namespaces:
15
15
 
16
- $ NS::OWL.uri # => "http://www.w3.org/2002/07/owl"
16
+ $ NS::OWL.uri # => #<URI::HTTP:0x00000000dcff78 URL:http://www.w3.org/2002/07/owl>
17
17
  $ NS::RDFS["hello"] # => #<URI::HTTP:0x00000000dcff78 URL:http://www.w3.org/2000/01/rdf-schema#hello>
18
18
 
19
19
  That's pretty much all there is to it.
20
20
 
21
21
  = Authors
22
22
 
23
- Slava Kravchenko <https://github.com/cordawyn/xml_schema>
23
+ Slava Kravchenko <slava.kravchenko@gmail.com>
data/lib/xml_schema/ns.rb CHANGED
@@ -13,15 +13,15 @@ module NS
13
13
  ns_module = self.const_set(name, Module.new)
14
14
  ns_module.module_eval <<-HERE
15
15
  def self.uri
16
- \"#{url}\"
16
+ URI(\"#{url}\")
17
17
  end
18
18
 
19
19
  def self.to_s
20
- \"\#{uri}#\"
20
+ \"#{url}\"
21
21
  end
22
22
 
23
23
  def self.[](value)
24
- URI.parse(\"\#{self}\#{value}\")
24
+ URI(\"\#{self}#\#{value}\")
25
25
  end
26
26
  HERE
27
27
  end
@@ -1,3 +1,3 @@
1
1
  module XmlSchema
2
- VERSION = "0.0.3"
2
+ VERSION = "0.1.0"
3
3
  end
data/lib/xml_schema.rb CHANGED
@@ -2,7 +2,6 @@ require 'time'
2
2
  require 'xml_schema/ns'
3
3
 
4
4
  module XmlSchema
5
-
6
5
  TYPES = %w(int boolean float dateTime time date string decimal double duration gYearMonth gYear gMonthDay gDay gMonth hexBinary base64Binary anyURI QName NOTATION)
7
6
 
8
7
 
@@ -14,19 +13,19 @@ module XmlSchema
14
13
  #++
15
14
  case object.class.name
16
15
  when "Fixnum", "Integer"
17
- NS::XMLSchema['int'].to_s
16
+ NS::XMLSchema['int']
18
17
  when "TrueClass", "FalseClass"
19
- NS::XMLSchema['boolean'].to_s
18
+ NS::XMLSchema['boolean']
20
19
  when "Float"
21
- NS::XMLSchema['float'].to_s
20
+ NS::XMLSchema['float']
22
21
  when "DateTime"
23
- NS::XMLSchema['dateTime'].to_s
22
+ NS::XMLSchema['dateTime']
24
23
  when "Time"
25
- NS::XMLSchema['time'].to_s
24
+ NS::XMLSchema['time']
26
25
  when "Date"
27
- NS::XMLSchema['date'].to_s
26
+ NS::XMLSchema['date']
28
27
  when "String"
29
- NS::XMLSchema['string'].to_s
28
+ NS::XMLSchema['string']
30
29
  else
31
30
  raise "#{object.class} cannot be coerced into any XMLSchema datatype"
32
31
  end
@@ -39,16 +38,17 @@ module XmlSchema
39
38
  # NOTE: removing language tag (e.g. "@en")
40
39
  full_literal = datatype_uri ? literal.sub(/@\w+$/, '') + "^^<#{datatype_uri}>" : literal.sub(/@\w+$/, '')
41
40
  literal_value, literal_type = full_literal.split('^^')
42
- datatype = if literal_type
43
- ns, l_type = literal_type.delete("<>").split('#')
44
- if ns == NS::XMLSchema.uri && TYPES.include?(l_type)
45
- l_type
41
+ datatype =
42
+ if literal_type
43
+ ns, l_type = literal_type.delete("<>").split('#')
44
+ if URI(ns) == NS::XMLSchema.uri && TYPES.include?(l_type)
45
+ l_type
46
+ else
47
+ raise "Incompatible datatype URI! (#{ns})"
48
+ end
46
49
  else
47
- raise "Incompatible datatype URI! (#{ns})"
50
+ 'string'
48
51
  end
49
- else
50
- 'string'
51
- end
52
52
 
53
53
  # clean-up the literal_value
54
54
  literal_value.sub!(/^["']/, '')
@@ -72,5 +72,4 @@ module XmlSchema
72
72
  literal_value
73
73
  end
74
74
  end
75
-
76
75
  end
@@ -53,31 +53,31 @@ class XmlSchemaTest < Test::Unit::TestCase
53
53
  end
54
54
 
55
55
  def test_should_return_datatype_for_integer
56
- assert_equal "http://www.w3.org/2001/XMLSchema#int", XmlSchema.datatype_of(42)
56
+ assert_equal URI("http://www.w3.org/2001/XMLSchema#int"), XmlSchema.datatype_of(42)
57
57
  end
58
58
 
59
59
  def test_should_return_datatype_for_boolean
60
- assert_equal "http://www.w3.org/2001/XMLSchema#boolean", XmlSchema.datatype_of(true)
60
+ assert_equal URI("http://www.w3.org/2001/XMLSchema#boolean"), XmlSchema.datatype_of(true)
61
61
  end
62
62
 
63
63
  def test_should_return_datatype_for_float
64
- assert_equal "http://www.w3.org/2001/XMLSchema#float", XmlSchema.datatype_of(11.11)
64
+ assert_equal URI("http://www.w3.org/2001/XMLSchema#float"), XmlSchema.datatype_of(11.11)
65
65
  end
66
66
 
67
67
  def test_should_return_datatype_for_datetime
68
- assert_equal "http://www.w3.org/2001/XMLSchema#dateTime", XmlSchema.datatype_of(DateTime.new)
68
+ assert_equal URI("http://www.w3.org/2001/XMLSchema#dateTime"), XmlSchema.datatype_of(DateTime.new)
69
69
  end
70
70
 
71
71
  def test_should_return_datatype_for_time
72
- assert_equal "http://www.w3.org/2001/XMLSchema#time", XmlSchema.datatype_of(Time.now)
72
+ assert_equal URI("http://www.w3.org/2001/XMLSchema#time"), XmlSchema.datatype_of(Time.now)
73
73
  end
74
74
 
75
75
  def test_should_return_datatype_for_date
76
- assert_equal "http://www.w3.org/2001/XMLSchema#date", XmlSchema.datatype_of(Date.today)
76
+ assert_equal URI("http://www.w3.org/2001/XMLSchema#date"), XmlSchema.datatype_of(Date.today)
77
77
  end
78
78
 
79
79
  def test_should_return_datatype_for_string
80
- assert_equal "http://www.w3.org/2001/XMLSchema#string", XmlSchema.datatype_of("test")
80
+ assert_equal URI("http://www.w3.org/2001/XMLSchema#string"), XmlSchema.datatype_of("test")
81
81
  end
82
82
 
83
83
  def test_should_raise_exception_on_unknown_class
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xml_schema
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-13 00:00:00.000000000 Z
12
+ date: 2012-07-23 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Helper methods and constants to handle XmlSchema
15
15
  email:
@@ -19,8 +19,10 @@ extensions: []
19
19
  extra_rdoc_files: []
20
20
  files:
21
21
  - .gitignore
22
+ - ChangeLog
22
23
  - Gemfile
23
24
  - Gemfile.lock
25
+ - LICENSE
24
26
  - README.rdoc
25
27
  - Rakefile
26
28
  - lib/xml_schema.rb
@@ -49,7 +51,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
49
51
  version: '0'
50
52
  requirements: []
51
53
  rubyforge_project: xml_schema
52
- rubygems_version: 1.8.15
54
+ rubygems_version: 1.8.24
53
55
  signing_key:
54
56
  specification_version: 3
55
57
  summary: Helper methods and constants to handle XmlSchema