xml_schema 0.0.2 → 0.0.3

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.
data/.gitignore CHANGED
@@ -3,3 +3,5 @@ pkg/*
3
3
  vendor/ruby
4
4
  vendor/rbx
5
5
  .rbx
6
+ .*~
7
+ *~
data/README.rdoc ADDED
@@ -0,0 +1,23 @@
1
+ = XML Schema
2
+
3
+ XmlSchema gem is a simple convertor utility for XML Schema (literal) datatypes to/from native Ruby objects.
4
+
5
+ = Usage
6
+
7
+ $ require "xml_schema"
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"
11
+
12
+ $ XmlSchema.instantiate("55^^<http://www.w3.org/2001/XMLSchema#int>") # => 55
13
+
14
+ XmlSchema also provides means to access and work with frequently used namespaces:
15
+
16
+ $ NS::OWL.uri # => "http://www.w3.org/2002/07/owl"
17
+ $ NS::RDFS["hello"] # => #<URI::HTTP:0x00000000dcff78 URL:http://www.w3.org/2000/01/rdf-schema#hello>
18
+
19
+ That's pretty much all there is to it.
20
+
21
+ = Authors
22
+
23
+ Slava Kravchenko <https://github.com/cordawyn/xml_schema>
data/Rakefile CHANGED
@@ -1,2 +1,9 @@
1
1
  require 'bundler'
2
2
  Bundler::GemHelper.install_tasks
3
+
4
+ require 'rake/testtask'
5
+ Rake::TestTask.new do |t|
6
+ t.libs << "test"
7
+ t.test_files = FileList['test/*_test.rb']
8
+ t.verbose = true
9
+ end
@@ -1,3 +1,3 @@
1
1
  module XmlSchema
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/xml_schema.rb CHANGED
@@ -1,16 +1,12 @@
1
- $:.unshift(File.dirname(__FILE__)) unless
2
- $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
-
4
- require 'xml_schema/ns'
5
1
  require 'time'
2
+ require 'xml_schema/ns'
6
3
 
7
- # Slightly modified xml_schema from Redlander project
8
4
  module XmlSchema
9
5
 
10
6
  TYPES = %w(int boolean float dateTime time date string decimal double duration gYearMonth gYear gMonthDay gDay gMonth hexBinary base64Binary anyURI QName NOTATION)
11
7
 
12
8
 
13
- # Obtain XML Schema datatype (as RDF node) for a Ruby object.
9
+ # Obtain XML Schema datatype URI for a Ruby object.
14
10
  def self.datatype_of(object)
15
11
  #--
16
12
  # TODO: decimal, double, duration (Range?), gYearMonth, gYear, gMonthDay, gDay, gMonth, hexBinary, base64Binary, anyURI, QName, NOTATION
@@ -32,7 +28,7 @@ module XmlSchema
32
28
  when "String"
33
29
  NS::XMLSchema['string'].to_s
34
30
  else
35
- raise RedlandError.new("#{object.class} cannot be coerced into any XMLSchema datatype")
31
+ raise "#{object.class} cannot be coerced into any XMLSchema datatype"
36
32
  end
37
33
  end
38
34
 
@@ -0,0 +1,2 @@
1
+ require "test/unit"
2
+ require "xml_schema"
@@ -0,0 +1,88 @@
1
+ require "test_helper"
2
+
3
+ class XmlSchemaTest < Test::Unit::TestCase
4
+ def test_should_instantiate_an_integer
5
+ value = XmlSchema.instantiate "55^^<http://www.w3.org/2001/XMLSchema#int>"
6
+ assert_equal 55, value
7
+ end
8
+
9
+ def test_should_instantiate_a_boolean_true
10
+ value = XmlSchema.instantiate "true^^<http://www.w3.org/2001/XMLSchema#boolean>"
11
+ assert_equal true, value
12
+ end
13
+
14
+ def test_should_instantiate_a_boolean_false
15
+ value = XmlSchema.instantiate "false^^<http://www.w3.org/2001/XMLSchema#boolean>"
16
+ assert_equal false, value
17
+ end
18
+
19
+ def test_should_instantiate_a_float
20
+ value = XmlSchema.instantiate "7.62^^<http://www.w3.org/2001/XMLSchema#float>"
21
+ assert_equal 7.62, value
22
+ end
23
+
24
+ def test_should_instantiate_a_datetime
25
+ value = XmlSchema.instantiate "2012-06-13T09:30:22^^<http://www.w3.org/2001/XMLSchema#dateTime>"
26
+ assert_equal DateTime.parse("2012-06-13T09:30:22"), value
27
+ end
28
+
29
+ def test_should_instantiate_a_time
30
+ value = XmlSchema.instantiate "2012-06-13T09:30:22^^<http://www.w3.org/2001/XMLSchema#time>"
31
+ assert_equal Time.parse("2012-06-13T09:30:22"), value
32
+ end
33
+
34
+ def test_should_instantiate_a_date
35
+ value = XmlSchema.instantiate "2012-06-13^^<http://www.w3.org/2001/XMLSchema#date>"
36
+ assert_equal Date.parse("2012-06-13"), value
37
+ end
38
+
39
+ def test_should_instantiate_a_string
40
+ value = XmlSchema.instantiate "hello^^<http://www.w3.org/2001/XMLSchema#string>"
41
+ assert_equal "hello", value
42
+ end
43
+
44
+ def test_should_instantiate_a_string_by_default
45
+ value = XmlSchema.instantiate "ahoy!"
46
+ assert_equal "ahoy!", value
47
+ end
48
+
49
+ def test_should_raise_exception_on_unknown_datatype
50
+ assert_raise RuntimeError do
51
+ XmlSchema.instantiate "???^^<http://www.w3.org/2001/XMLSchema#unknown>"
52
+ end
53
+ end
54
+
55
+ def test_should_return_datatype_for_integer
56
+ assert_equal "http://www.w3.org/2001/XMLSchema#int", XmlSchema.datatype_of(42)
57
+ end
58
+
59
+ def test_should_return_datatype_for_boolean
60
+ assert_equal "http://www.w3.org/2001/XMLSchema#boolean", XmlSchema.datatype_of(true)
61
+ end
62
+
63
+ def test_should_return_datatype_for_float
64
+ assert_equal "http://www.w3.org/2001/XMLSchema#float", XmlSchema.datatype_of(11.11)
65
+ end
66
+
67
+ def test_should_return_datatype_for_datetime
68
+ assert_equal "http://www.w3.org/2001/XMLSchema#dateTime", XmlSchema.datatype_of(DateTime.new)
69
+ end
70
+
71
+ def test_should_return_datatype_for_time
72
+ assert_equal "http://www.w3.org/2001/XMLSchema#time", XmlSchema.datatype_of(Time.now)
73
+ end
74
+
75
+ def test_should_return_datatype_for_date
76
+ assert_equal "http://www.w3.org/2001/XMLSchema#date", XmlSchema.datatype_of(Date.today)
77
+ end
78
+
79
+ def test_should_return_datatype_for_string
80
+ assert_equal "http://www.w3.org/2001/XMLSchema#string", XmlSchema.datatype_of("test")
81
+ end
82
+
83
+ def test_should_raise_exception_on_unknown_class
84
+ assert_raise RuntimeError do
85
+ XmlSchema.datatype_of(Object.new)
86
+ end
87
+ end
88
+ end
metadata CHANGED
@@ -1,75 +1,57 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: xml_schema
3
- version: !ruby/object:Gem::Version
4
- hash: 1317335842608397244
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 2
10
- version: 0.0.2
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Slava Kravchenko
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-11-13 00:00:00 +03:00
19
- default_executable:
12
+ date: 2012-06-13 00:00:00.000000000 Z
20
13
  dependencies: []
21
-
22
14
  description: Helper methods and constants to handle XmlSchema
23
- email:
15
+ email:
24
16
  - slava.kravchenko@gmail.com
25
17
  executables: []
26
-
27
18
  extensions: []
28
-
29
19
  extra_rdoc_files: []
30
-
31
- files:
20
+ files:
32
21
  - .gitignore
33
22
  - Gemfile
34
23
  - Gemfile.lock
24
+ - README.rdoc
35
25
  - Rakefile
36
26
  - lib/xml_schema.rb
37
27
  - lib/xml_schema/ns.rb
38
28
  - lib/xml_schema/version.rb
29
+ - test/test_helper.rb
30
+ - test/xml_schema_test.rb
39
31
  - xml_schema.gemspec
40
- has_rdoc: true
41
32
  homepage: https://github.com/cordawyn/xml_schema
42
33
  licenses: []
43
-
44
34
  post_install_message:
45
35
  rdoc_options: []
46
-
47
- require_paths:
36
+ require_paths:
48
37
  - lib
49
- required_ruby_version: !ruby/object:Gem::Requirement
38
+ required_ruby_version: !ruby/object:Gem::Requirement
50
39
  none: false
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- hash: 2002549777813010636
55
- segments:
56
- - 0
57
- version: "0"
58
- required_rubygems_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
45
  none: false
60
- requirements:
61
- - - ">="
62
- - !ruby/object:Gem::Version
63
- hash: 2002549777813010636
64
- segments:
65
- - 0
66
- version: "0"
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
67
50
  requirements: []
68
-
69
51
  rubyforge_project: xml_schema
70
- rubygems_version: 1.5.2
52
+ rubygems_version: 1.8.15
71
53
  signing_key:
72
54
  specification_version: 3
73
55
  summary: Helper methods and constants to handle XmlSchema
74
56
  test_files: []
75
-
57
+ has_rdoc: