sdl4r 0.9.8 → 0.9.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/CHANGELOG +14 -1
  2. data/README +4 -4
  3. data/Rakefile +15 -12
  4. data/TODO +11 -4
  5. data/lib/sdl4r/parser.rb +25 -33
  6. data/lib/sdl4r/parser/token.rb +1 -1
  7. data/lib/sdl4r/sdl4r.rb +50 -22
  8. data/lib/sdl4r/sdl_time_span.rb +2 -2
  9. data/lib/sdl4r/serializer.rb +152 -0
  10. data/lib/sdl4r/tag.rb +15 -1
  11. data/test/sdl4r/parser_test.rb +5 -0
  12. data/test/sdl4r/serializer_test.rb +78 -0
  13. data/test/sdl4r/tag_test.rb +20 -1
  14. metadata +52 -81
  15. data/doc/classes/SDL4R.html +0 -408
  16. data/doc/classes/SDL4R/Parser.html +0 -190
  17. data/doc/classes/SDL4R/ParserTest.html +0 -385
  18. data/doc/classes/SDL4R/SDL4RTest.html +0 -532
  19. data/doc/classes/SDL4R/SDLTest.html +0 -77
  20. data/doc/classes/SDL4R/SdlBinary.html +0 -188
  21. data/doc/classes/SDL4R/SdlParseError.html +0 -110
  22. data/doc/classes/SDL4R/SdlTimeSpan.html +0 -637
  23. data/doc/classes/SDL4R/Tag.html +0 -1249
  24. data/doc/classes/SDL4R/TagTest.html +0 -292
  25. data/doc/created.rid +0 -1
  26. data/doc/files/CHANGELOG.html +0 -200
  27. data/doc/files/LICENSE.html +0 -497
  28. data/doc/files/README.html +0 -406
  29. data/doc/files/lib/sdl4r/parser/reader_rb.html +0 -54
  30. data/doc/files/lib/sdl4r/parser/time_span_with_zone_rb.html +0 -54
  31. data/doc/files/lib/sdl4r/parser/token_rb.html +0 -54
  32. data/doc/files/lib/sdl4r/parser/tokenizer_rb.html +0 -54
  33. data/doc/files/lib/sdl4r/parser_rb.html +0 -62
  34. data/doc/files/lib/sdl4r/sdl4r_rb.html +0 -64
  35. data/doc/files/lib/sdl4r/sdl_binary_rb.html +0 -54
  36. data/doc/files/lib/sdl4r/sdl_parse_error_rb.html +0 -54
  37. data/doc/files/lib/sdl4r/sdl_time_span_rb.html +0 -54
  38. data/doc/files/lib/sdl4r/tag_rb.html +0 -64
  39. data/doc/files/lib/sdl4r_rb.html +0 -54
  40. data/doc/files/test/sdl4r/parser_test_rb.html +0 -64
  41. data/doc/files/test/sdl4r/sdl4r_test_rb.html +0 -67
  42. data/doc/files/test/sdl4r/sdl_test_rb.html +0 -64
  43. data/doc/files/test/sdl4r/tag_test_rb.html +0 -64
  44. data/doc/fr_class_index.html +0 -19
  45. data/doc/fr_file_index.html +0 -37
  46. data/doc/fr_method_index.html +0 -4711
  47. data/doc/index.html +0 -15
  48. data/doc/rdoc-style.css +0 -328
@@ -498,6 +498,10 @@ module SDL4R
498
498
  }
499
499
  nil
500
500
  end
501
+
502
+ def has_values?
503
+ !@values.empty?
504
+ end
501
505
 
502
506
  # set_attribute(key, value)
503
507
  # set_attribute(namespace, key, value)
@@ -568,6 +572,10 @@ module SDL4R
568
572
  return false
569
573
  end
570
574
  end
575
+
576
+ def has_attributes?
577
+ !@attributesByNamespace.empty?
578
+ end
571
579
 
572
580
  # Returns a Hash of the attributes of the specified +namespace+ (default is all) or enumerates
573
581
  # them.
@@ -815,13 +823,19 @@ module SDL4R
815
823
  end
816
824
 
817
825
  # output values
826
+ previous_value = nil
818
827
  values do |value|
819
828
  if skip_value_space
820
829
  skip_value_space = false
821
830
  else
822
831
  s << " "
823
832
  end
824
- s << SDL4R.format(value, true, line_prefix, indent)
833
+ if value.is_a?(SdlTimeSpan) and previous_value.is_a?(Date)
834
+ s << value.to_s(true)
835
+ else
836
+ s << SDL4R.format(value, true, line_prefix, indent)
837
+ end
838
+ previous_value = value
825
839
  end
826
840
 
827
841
  # output attributes
@@ -141,6 +141,11 @@ EOS
141
141
  tag1 = parse_one_tag1("tag1 2005/12/05")
142
142
  date = tag1.value
143
143
  assert_equal(Date.civil(2005, 12, 5), date, "date value")
144
+
145
+ # check negative years
146
+ tag1 = parse_one_tag1("tag1 -145/12/23");
147
+ date = tag1.value
148
+ assert_equal(Date.civil(-145, 12, 23), date, "negative year")
144
149
  end
145
150
 
146
151
  def test_time
@@ -0,0 +1,78 @@
1
+ #!/usr/bin/env ruby -w
2
+ # encoding: UTF-8
3
+
4
+ #--
5
+ # Simple Declarative Language (SDL) for Ruby
6
+ # Copyright 2005 Ikayzo, inc.
7
+ #
8
+ # This program is free software. You can distribute or modify it under the
9
+ # terms of the GNU Lesser General Public License version 2.1 as published by
10
+ # the Free Software Foundation.
11
+ #
12
+ # This program is distributed AS IS and WITHOUT WARRANTY. OF ANY KIND,
13
+ # INCLUDING MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
14
+ # See the GNU Lesser General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public License
17
+ # along with this program; if not, contact the Free Software Foundation, Inc.,
18
+ # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
+ #++
20
+
21
+ # Work-around a bug in NetBeans (http://netbeans.org/bugzilla/show_bug.cgi?id=188653)
22
+ $:[0] = File.join(File.dirname(__FILE__),'../../lib') if ENV["NB_EXEC_EXTEXECUTION_PROCESS_UUID"]
23
+
24
+ module SDL4R
25
+
26
+ require 'ostruct'
27
+ require 'date'
28
+
29
+ require 'sdl4r/serializer'
30
+
31
+ class SerializerTest < Test::Unit::TestCase
32
+
33
+ def test_basic_open_struct
34
+ serializer = Serializer.new
35
+
36
+ car = OpenStruct.new
37
+ car.brand = "Opel"
38
+ car.wheels = 4
39
+ car.max_speed = 223.5
40
+ car.radio = OpenStruct.new
41
+ car.radio.brand = "Pioneer"
42
+ car.radio.signal_noise_ratio = 90
43
+ car.radio.construction_date = Date.civil(2005, 12, 5)
44
+
45
+ # serialize and check
46
+ tag = serializer.serialize(car)
47
+
48
+ assert_equal SDL4R::ROOT_TAG_NAME, tag.name
49
+ assert_equal(
50
+ { "brand" => car.brand, "wheels" => car.wheels, "max_speed" => car.max_speed },
51
+ tag.attributes)
52
+ assert_equal 1, tag.children.length
53
+ assert_equal 'radio', tag.children[0].name
54
+ assert_equal(
55
+ { 'brand' => car.radio.brand, 'signal_noise_ratio' => car.radio.signal_noise_ratio,
56
+ 'construction_date' => car.radio.construction_date },
57
+ tag.child('radio').attributes)
58
+ assert !car.radio.has_children?
59
+
60
+ # deserialize and check
61
+ car2 = serializer.deserialize(tag)
62
+ assert_equal car.brand, car2.brand
63
+ assert_equal car.wheels, car2.wheels
64
+ assert_equal car.max_speed, car2.max_speed
65
+ assert_equal car.radio.brand, car2.radio.brand
66
+ assert_equal car.radio.signal_noise_ratio, car2.radio.signal_noise_ratio
67
+ assert_equal car.radio.construction_date, car2.radio.construction_date
68
+ end
69
+
70
+ def test_struct
71
+ dir = File.dirname(__FILE__)
72
+ o = Serializer.new.deserialize(SDL4R::read(Pathname.new(dir + '/' + "test_structures.sdl")))
73
+ p o
74
+ end
75
+
76
+ end
77
+
78
+ end
@@ -622,6 +622,25 @@ EOF
622
622
  output)
623
623
  end
624
624
 
625
- end
625
+ # Check that having a timespan after a date in a tag values doesn't fail when loaded.
626
+ #
627
+ def test_write_parse_date_timespan
628
+ tag1 = Tag.new("tag1") { |t|
629
+ t.values = [ "123", Date.today(), SdlTimeSpan.new(0, 12, 34, 56), 456 ]
630
+ }
631
+
632
+ parsed_tag1 = SDL4R::read(tag1.to_s).child("tag1")
633
+
634
+ assert_equal tag1.values, parsed_tag1.values
635
+ end
626
636
 
637
+ def test_symbol_as_value
638
+ tag1 = Tag.new("tag1") {
639
+ set_attribute("type", :square)
640
+ }
641
+
642
+ assert_equal "square", tag1.attribute("type")
643
+ end
644
+
645
+ end
627
646
  end
metadata CHANGED
@@ -3,19 +3,19 @@ name: sdl4r
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
- - 0
7
- - 9
8
- - 8
9
- version: 0.9.8
6
+ - 0
7
+ - 9
8
+ - 9
9
+ version: 0.9.9
10
10
  platform: ruby
11
11
  authors:
12
- - Philippe Vosges
13
- - Daniel Leuck
12
+ - Philippe Vosges
13
+ - Daniel Leuck
14
14
  autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-16 00:00:00 +09:00
18
+ date: 2010-11-19 00:00:00 +09:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -28,94 +28,65 @@ extensions: []
28
28
  extra_rdoc_files: []
29
29
 
30
30
  files:
31
- - lib/sdl4r.rb
32
- - lib/sdl4r/sdl_time_span.rb
33
- - lib/sdl4r/sdl_parse_error.rb
34
- - lib/sdl4r/tag.rb
35
- - lib/sdl4r/parser.rb
36
- - lib/sdl4r/sdl_binary.rb
37
- - lib/sdl4r/sdl4r.rb
38
- - lib/sdl4r/parser/reader.rb
39
- - lib/sdl4r/parser/tokenizer.rb
40
- - lib/sdl4r/parser/token.rb
41
- - lib/sdl4r/parser/time_span_with_zone.rb
42
- - README
43
- - Rakefile
44
- - LICENSE
45
- - CHANGELOG
46
- - TODO
47
- - test/sdl4r/parser_test.rb
48
- - test/sdl4r/tag_test.rb
49
- - test/sdl4r/sdl_test.rb
50
- - test/sdl4r/test_structures.sdl
51
- - test/sdl4r/test_basic_types.sdl
52
- - test/sdl4r/sdl4r_test.rb
53
- - doc/rdoc-style.css
54
- - doc/fr_file_index.html
55
- - doc/fr_class_index.html
56
- - doc/fr_method_index.html
57
- - doc/index.html
58
- - doc/created.rid
59
- - doc/files/README.html
60
- - doc/files/LICENSE.html
61
- - doc/files/CHANGELOG.html
62
- - doc/files/lib/sdl4r_rb.html
63
- - doc/files/lib/sdl4r/sdl_time_span_rb.html
64
- - doc/files/lib/sdl4r/tag_rb.html
65
- - doc/files/lib/sdl4r/sdl_parse_error_rb.html
66
- - doc/files/lib/sdl4r/parser_rb.html
67
- - doc/files/lib/sdl4r/sdl4r_rb.html
68
- - doc/files/lib/sdl4r/sdl_binary_rb.html
69
- - doc/files/lib/sdl4r/parser/time_span_with_zone_rb.html
70
- - doc/files/lib/sdl4r/parser/reader_rb.html
71
- - doc/files/lib/sdl4r/parser/tokenizer_rb.html
72
- - doc/files/lib/sdl4r/parser/token_rb.html
73
- - doc/files/test/sdl4r/tag_test_rb.html
74
- - doc/files/test/sdl4r/sdl_test_rb.html
75
- - doc/files/test/sdl4r/parser_test_rb.html
76
- - doc/files/test/sdl4r/sdl4r_test_rb.html
77
- - doc/classes/SDL4R.html
78
- - doc/classes/SDL4R/SdlTimeSpan.html
79
- - doc/classes/SDL4R/SdlParseError.html
80
- - doc/classes/SDL4R/Tag.html
81
- - doc/classes/SDL4R/Parser.html
82
- - doc/classes/SDL4R/SDLTest.html
83
- - doc/classes/SDL4R/TagTest.html
84
- - doc/classes/SDL4R/SdlBinary.html
85
- - doc/classes/SDL4R/ParserTest.html
86
- - doc/classes/SDL4R/SDL4RTest.html
31
+ - lib/sdl4r.rb
32
+ - lib/sdl4r/parser/reader.rb
33
+ - lib/sdl4r/parser/time_span_with_zone.rb
34
+ - lib/sdl4r/parser/token.rb
35
+ - lib/sdl4r/parser/tokenizer.rb
36
+ - lib/sdl4r/parser.rb
37
+ - lib/sdl4r/sdl4r.rb
38
+ - lib/sdl4r/sdl_binary.rb
39
+ - lib/sdl4r/sdl_parse_error.rb
40
+ - lib/sdl4r/sdl_time_span.rb
41
+ - lib/sdl4r/serializer.rb
42
+ - lib/sdl4r/tag.rb
43
+ - CHANGELOG
44
+ - LICENSE
45
+ - Rakefile
46
+ - README
47
+ - TODO
48
+ - test/sdl4r/parser_test.rb
49
+ - test/sdl4r/sdl4r_test.rb
50
+ - test/sdl4r/sdl_test.rb
51
+ - test/sdl4r/serializer_test.rb
52
+ - test/sdl4r/tag_test.rb
53
+ - test/sdl4r/test_basic_types.sdl
54
+ - test/sdl4r/test_structures.sdl
87
55
  has_rdoc: true
88
- homepage: http://www.ikayzo.org/confluence/display/SDL/Home
56
+ homepage: http://sdl4r.rubyforge.org/
89
57
  licenses: []
90
58
 
91
59
  post_install_message:
92
60
  rdoc_options: []
93
61
 
94
62
  require_paths:
95
- - lib
63
+ - lib
96
64
  required_ruby_version: !ruby/object:Gem::Requirement
65
+ none: false
97
66
  requirements:
98
- - - ">="
99
- - !ruby/object:Gem::Version
100
- segments:
101
- - 0
102
- version: "0"
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ segments:
70
+ - 0
71
+ version: "0"
103
72
  required_rubygems_version: !ruby/object:Gem::Requirement
73
+ none: false
104
74
  requirements:
105
- - - ">="
106
- - !ruby/object:Gem::Version
107
- segments:
108
- - 0
109
- version: "0"
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ segments:
78
+ - 0
79
+ version: "0"
110
80
  requirements:
111
- - none
81
+ - none
112
82
  rubyforge_project: sdl4r
113
- rubygems_version: 1.3.6
83
+ rubygems_version: 1.3.7
114
84
  signing_key:
115
85
  specification_version: 3
116
86
  summary: Simple Declarative Language for Ruby library
117
87
  test_files:
118
- - test/sdl4r/parser_test.rb
119
- - test/sdl4r/tag_test.rb
120
- - test/sdl4r/sdl_test.rb
121
- - test/sdl4r/sdl4r_test.rb
88
+ - test/sdl4r/parser_test.rb
89
+ - test/sdl4r/sdl4r_test.rb
90
+ - test/sdl4r/sdl_test.rb
91
+ - test/sdl4r/serializer_test.rb
92
+ - test/sdl4r/tag_test.rb
@@ -1,408 +0,0 @@
1
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2
- <html lang='en'>
3
- <head>
4
- <title>: SDL4R [RDoc: Simple Declarative Language for Ruby]</title>
5
- <meta content='text/html; charset=utf-8' http-equiv='Content-Type'>
6
- <link href='../rdoc-style.css' media='screen' rel='stylesheet' type='text/css'>
7
- <script type='text/javascript'>
8
- //<![CDATA[
9
- function popupCode(url) {
10
- window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
11
- }
12
-
13
- function toggleCode(id) {
14
- var code = document.getElementById(id)
15
-
16
- code.style.display = code.style.display != 'block' ? 'block' : 'none'
17
- return true
18
- }
19
-
20
- // Make codeblocks hidden by default
21
- document.writeln('<' + 'style type="text/css">.method .source pre { display: none }<\/style>')
22
- //]]>
23
- </script>
24
- </head>
25
- <body class='page'>
26
- <div class='class' id='wrapper'>
27
- <div class='header'>
28
- <h1 class='name'>
29
- <span class='type'>Module</span>
30
- SDL4R
31
- </h1>
32
- <ol class='paths'>
33
- <li>
34
- <a href="../files/lib/sdl4r/sdl_time_span_rb.html">lib/sdl4r/sdl_time_span.rb</a>
35
- </li>
36
- <li class='other'>
37
- <a href="../files/lib/sdl4r/sdl_parse_error_rb.html">lib/sdl4r/sdl_parse_error.rb</a>
38
- </li>
39
- <li class='other'>
40
- <a href="../files/lib/sdl4r/tag_rb.html">lib/sdl4r/tag.rb</a>
41
- </li>
42
- <li class='other'>
43
- <a href="../files/lib/sdl4r/parser_rb.html">lib/sdl4r/parser.rb</a>
44
- </li>
45
- <li class='other'>
46
- <a href="../files/lib/sdl4r/sdl_binary_rb.html">lib/sdl4r/sdl_binary.rb</a>
47
- </li>
48
- <li class='other'>
49
- <a href="../files/lib/sdl4r/parser/reader_rb.html">lib/sdl4r/parser/reader.rb</a>
50
- </li>
51
- <li class='other'>
52
- <a href="../files/lib/sdl4r/parser/token_rb.html">lib/sdl4r/parser/token.rb</a>
53
- </li>
54
- <li class='other'>
55
- <a href="../files/lib/sdl4r/parser/tokenizer_rb.html">lib/sdl4r/parser/tokenizer.rb</a>
56
- </li>
57
- <li class='other'>
58
- <a href="../files/lib/sdl4r/parser/time_span_with_zone_rb.html">lib/sdl4r/parser/time_span_with_zone.rb</a>
59
- </li>
60
- <li class='other'>
61
- <a href="../files/lib/sdl4r/sdl4r_rb.html">lib/sdl4r/sdl4r.rb</a>
62
- </li>
63
- <li class='other'>
64
- <a href="../files/test/sdl4r/parser_test_rb.html">test/sdl4r/parser_test.rb</a>
65
- </li>
66
- <li class='other'>
67
- <a href="../files/test/sdl4r/tag_test_rb.html">test/sdl4r/tag_test.rb</a>
68
- </li>
69
- <li class='other'>
70
- <a href="../files/test/sdl4r/sdl_test_rb.html">test/sdl4r/sdl_test.rb</a>
71
- </li>
72
- <li class='other'>
73
- <a href="../files/test/sdl4r/sdl4r_test_rb.html">test/sdl4r/sdl4r_test.rb</a>
74
- </li>
75
- <li>
76
- <a class='show' href='#' onclick='this.parentNode.parentNode.className += " expanded"; this.parentNode.removeChild(this); return false'>show all</a>
77
- </li>
78
- </ol>
79
- </div>
80
- <div id='content'>
81
- <div id='text'>
82
- <div id='description'>
83
- <hr size="1"></hr><p>
84
- Gathers utility methods.
85
- </p>
86
- <hr size="1"></hr><p>
87
- Work-around a bug in NetBeans (<a
88
- href="http://netbeans.org/bugzilla/show_bug.cgi?id=188653">netbeans.org/bugzilla/show_bug.cgi?id=188653</a>)
89
- $:[0] = File.join(File.dirname(<em>FILE</em>),&#8217;../../lib&#8217;) if
90
- ENV[&#8220;NB_EXEC_EXTEXECUTION_PROCESS_UUID&#8220;]
91
- </p>
92
- </div>
93
- <div id='method-list'>
94
- <h2>Methods</h2>
95
- <h3>public class</h3>
96
- <ol>
97
- <li><a href="#M000001">SdlBinary</a></li>
98
- <li><a href="#M000004">coerce_or_fail</a></li>
99
- <li><a href="#M000002">format</a></li>
100
- <li><a href="#M000003">new_date_time</a></li>
101
- <li><a href="#M000006">read</a></li>
102
- <li><a href="#M000009">to_attribute_map</a></li>
103
- <li><a href="#M000007">to_value</a></li>
104
- <li><a href="#M000008">to_value_array</a></li>
105
- <li><a href="#M000005">validate_identifier</a></li>
106
- </ol>
107
- </div>
108
- <div id='section'>
109
- <div id='class-list'>
110
- <h2>Classes and Modules</h2>
111
- Class <a href="SDL4R/Parser.html" class="link">SDL4R::Parser</a><br />
112
- Class <a href="SDL4R/ParserTest.html" class="link">SDL4R::ParserTest</a><br />
113
- Class <a href="SDL4R/SDL4RTest.html" class="link">SDL4R::SDL4RTest</a><br />
114
- Class <a href="SDL4R/SDLTest.html" class="link">SDL4R::SDLTest</a><br />
115
- Class <a href="SDL4R/SdlBinary.html" class="link">SDL4R::SdlBinary</a><br />
116
- Class <a href="SDL4R/SdlParseError.html" class="link">SDL4R::SdlParseError</a><br />
117
- Class <a href="SDL4R/SdlTimeSpan.html" class="link">SDL4R::SdlTimeSpan</a><br />
118
- Class <a href="SDL4R/Tag.html" class="link">SDL4R::Tag</a><br />
119
- Class <a href="SDL4R/TagTest.html" class="link">SDL4R::TagTest</a><br />
120
- </div>
121
- <div id='constants-list'>
122
- <h2>Constants</h2>
123
- <div class='name-list'>
124
- <table summary='Constants'>
125
- <tr class='top-aligned-row context-row'>
126
- <td class='context-item-name'>MAX_INTEGER_32</td>
127
- <td>=</td>
128
- <td class='context-item-value'>2**31 - 1</td>
129
- </tr>
130
- <tr class='top-aligned-row context-row'>
131
- <td class='context-item-name'>MIN_INTEGER_32</td>
132
- <td>=</td>
133
- <td class='context-item-value'>-(2**31)</td>
134
- </tr>
135
- <tr class='top-aligned-row context-row'>
136
- <td class='context-item-name'>MAX_INTEGER_64</td>
137
- <td>=</td>
138
- <td class='context-item-value'>2**63 - 1</td>
139
- </tr>
140
- <tr class='top-aligned-row context-row'>
141
- <td class='context-item-name'>MIN_INTEGER_64</td>
142
- <td>=</td>
143
- <td class='context-item-value'>-(2**63)</td>
144
- </tr>
145
- <tr class='top-aligned-row context-row'>
146
- <td class='context-item-name'>BASE64_WRAP_LINE_LENGTH</td>
147
- <td>=</td>
148
- <td class='context-item-value'>72</td>
149
- </tr>
150
- <tr class='top-aligned-row context-row'>
151
- <td class='context-item-name'>ANONYMOUS_TAG_NAME</td>
152
- <td>=</td>
153
- <td class='context-item-value'>&quot;content&quot;</td>
154
- </tr>
155
- <tr class='top-aligned-row context-row'>
156
- <td class='context-item-name'>ROOT_TAG_NAME</td>
157
- <td>=</td>
158
- <td class='context-item-value'>&quot;root&quot;</td>
159
- </tr>
160
- <tr class='top-aligned-row context-row'>
161
- <td class='context-item-name'>ESCAPED_QUOTES</td>
162
- <td>=</td>
163
- <td class='context-item-value'>{ &quot;\&quot;&quot; =&gt; &quot;\\\&quot;&quot;, &quot;'&quot; =&gt; &quot;\\'&quot;, &quot;`&quot; =&gt; &quot;\\`&quot;, }</td>
164
- </tr>
165
- <tr class='top-aligned-row context-row'>
166
- <td class='context-item-name'>ESCAPED_CHARS</td>
167
- <td>=</td>
168
- <td class='context-item-value'>{ &quot;\\&quot; =&gt; &quot;\\\\&quot;, &quot;\t&quot; =&gt; &quot;\\t&quot;, &quot;\r&quot; =&gt; &quot;\\r&quot;, &quot;\n&quot; =&gt; &quot;\\n&quot;, }</td>
169
- </tr>
170
- </table>
171
- </div>
172
- </div>
173
- <div id='methods'>
174
- <h2>Public class methods</h2>
175
- <div class='method public-class' id='method-M000001'>
176
- <a name='M000001'></a>
177
- <div class='synopsis'>
178
- <span class='name'>SdlBinary</span>
179
- <span class='arguments'>(o)</span>
180
- </div>
181
- <div class='description'>
182
- <p>
183
- Try to coerce &#8216;o&#8217; into a <a
184
- href="SDL4R.html#M000001">SdlBinary</a>. Raise an ArgumentError if it
185
- fails.
186
- </p>
187
- </div>
188
- <div class='source'>
189
- <a class='source-toggle' href='#' onclick="toggleCode('M000001-source'); return false">
190
- [show source]
191
- </a>
192
- <pre id='M000001-source'> <span class="ruby-comment cmt"># File lib/sdl4r/sdl_binary.rb, line 72</span>&#x000A;72: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">SdlBinary</span>(<span class="ruby-identifier">o</span>)&#x000A;73: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">SdlBinary</span>&#x000A;74: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">o</span>&#x000A;75: <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">String</span>&#x000A;76: <span class="ruby-keyword kw">return</span> <span class="ruby-constant">SdlBinary</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">o</span>)&#x000A;77: <span class="ruby-keyword kw">else</span>&#x000A;78: <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">&quot;can't coerce argument&quot;</span>&#x000A;79: <span class="ruby-keyword kw">end</span>&#x000A;80: <span class="ruby-keyword kw">end</span></pre>
193
- </div>
194
- </div>
195
- <div class='method public-class' id='method-M000004'>
196
- <a name='M000004'></a>
197
- <div class='synopsis'>
198
- <span class='name'>coerce_or_fail</span>
199
- <span class='arguments'>(o)</span>
200
- </div>
201
- <div class='description'>
202
- <p>
203
- Coerce the type to a standard SDL type or raises an ArgumentError.
204
- </p>
205
- <p>
206
- Returns <tt>o</tt> if of the following classes: NilClass, String, Numeric,
207
- Float, TrueClass, FalseClass, Date, DateTime, Time, <a
208
- href="SDL4R/SdlTimeSpan.html">SdlTimeSpan</a>, <a
209
- href="SDL4R.html#M000001">SdlBinary</a>,
210
- </p>
211
- <p>
212
- Rationals are turned into Floats using Rational#to_f.
213
- </p>
214
- </div>
215
- <div class='source'>
216
- <a class='source-toggle' href='#' onclick="toggleCode('M000004-source'); return false">
217
- [show source]
218
- </a>
219
- <pre id='M000004-source'> <span class="ruby-comment cmt"># File lib/sdl4r/sdl4r.rb, line 156</span>&#x000A;156: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">coerce_or_fail</span>(<span class="ruby-identifier">o</span>)&#x000A;157: <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">o</span>&#x000A;158: &#x000A;159: <span class="ruby-keyword kw">when</span> <span class="ruby-constant">Rational</span>&#x000A;160: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">to_f</span>&#x000A;161: &#x000A;162: <span class="ruby-keyword kw">when</span> <span class="ruby-constant">NilClass</span>,&#x000A;163: <span class="ruby-constant">String</span>,&#x000A;164: <span class="ruby-constant">Numeric</span>,&#x000A;165: <span class="ruby-constant">Float</span>,&#x000A;166: <span class="ruby-constant">TrueClass</span>,&#x000A;167: <span class="ruby-constant">FalseClass</span>,&#x000A;168: <span class="ruby-constant">Date</span>,&#x000A;169: <span class="ruby-constant">DateTime</span>,&#x000A;170: <span class="ruby-constant">Time</span>,&#x000A;171: <span class="ruby-constant">SdlTimeSpan</span>,&#x000A;172: <span class="ruby-constant">SdlBinary</span>&#x000A;173: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">o</span>&#x000A;174: &#x000A;175: <span class="ruby-keyword kw">end</span>&#x000A;176: &#x000A;177: <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">&quot;#{o.class.name} is not coercible to an SDL type&quot;</span>&#x000A;178: <span class="ruby-keyword kw">end</span></pre>
220
- </div>
221
- </div>
222
- <div class='method public-class' id='method-M000002'>
223
- <a name='M000002'></a>
224
- <div class='synopsis'>
225
- <span class='name'>format</span>
226
- <span class='arguments'>(o, add_quotes = true, line_prefix = &quot;&quot;, indent = &quot;\t&quot;)</span>
227
- </div>
228
- <div class='description'>
229
- <p>
230
- Creates an SDL string representation for a given object and returns it.
231
- </p>
232
- <table>
233
- <tr><td valign="top"><tt>o</tt>:</td><td>the object to format
234
-
235
- </td></tr>
236
- <tr><td valign="top"><tt>add_quotes</tt>:</td><td>indicates whether quotes will be added to Strings and characters (true by
237
- default)
238
-
239
- </td></tr>
240
- <tr><td valign="top"><tt>line_prefix</tt>:</td><td>the line prefix to use (&#8220;&#8221; by default)
241
-
242
- </td></tr>
243
- <tr><td valign="top"><tt>indent</tt>:</td><td>the indent string to use (&#8220;t&#8220; by default)
244
-
245
- </td></tr>
246
- </table>
247
- </div>
248
- <div class='source'>
249
- <a class='source-toggle' href='#' onclick="toggleCode('M000002-source'); return false">
250
- [show source]
251
- </a>
252
- <pre id='M000002-source'> <span class="ruby-comment cmt"># File lib/sdl4r/sdl4r.rb, line 47</span>&#x000A; 47: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">format</span>(<span class="ruby-identifier">o</span>, <span class="ruby-identifier">add_quotes</span> = <span class="ruby-keyword kw">true</span>, <span class="ruby-identifier">line_prefix</span> = <span class="ruby-value str">&quot;&quot;</span>, <span class="ruby-identifier">indent</span> = <span class="ruby-value str">&quot;\t&quot;</span>)&#x000A; 48: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">String</span>)&#x000A; 49: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">add_quotes</span>&#x000A; 50: <span class="ruby-identifier">o_length</span> = <span class="ruby-value">0</span>&#x000A; 51: <span class="ruby-identifier">o</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp re">/./</span><span class="ruby-identifier">m</span>) { <span class="ruby-identifier">o_length</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span> } <span class="ruby-comment cmt"># counts the number of chars (as opposed of bytes)</span>&#x000A; 52: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">o_length</span> <span class="ruby-operator">==</span> <span class="ruby-value">1</span>&#x000A; 53: <span class="ruby-keyword kw">return</span> <span class="ruby-value str">&quot;'&quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">escape</span>(<span class="ruby-identifier">o</span>, <span class="ruby-value str">&quot;'&quot;</span>) <span class="ruby-operator">+</span> <span class="ruby-value str">&quot;'&quot;</span>&#x000A; 54: <span class="ruby-keyword kw">else</span>&#x000A; 55: <span class="ruby-keyword kw">return</span> <span class="ruby-value str">'&quot;'</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">escape</span>(<span class="ruby-identifier">o</span>, <span class="ruby-value str">'&quot;'</span>) <span class="ruby-operator">+</span> <span class="ruby-value str">'&quot;'</span>&#x000A; 56: <span class="ruby-keyword kw">end</span>&#x000A; 57: <span class="ruby-keyword kw">else</span>&#x000A; 58: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">escape</span>(<span class="ruby-identifier">o</span>)&#x000A; 59: <span class="ruby-keyword kw">end</span>&#x000A; 60: &#x000A; 61: <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Bignum</span>)&#x000A; 62: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-operator">+</span> <span class="ruby-value str">&quot;BD&quot;</span>&#x000A; 63: &#x000A; 64: <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Integer</span>)&#x000A; 65: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">MIN_INTEGER_32</span> <span class="ruby-operator">&lt;=</span> <span class="ruby-identifier">o</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">o</span> <span class="ruby-operator">&lt;=</span> <span class="ruby-constant">MAX_INTEGER_32</span>&#x000A; 66: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">to_s</span>&#x000A; 67: <span class="ruby-keyword kw">elsif</span> <span class="ruby-constant">MIN_INTEGER_64</span> <span class="ruby-operator">&lt;=</span> <span class="ruby-identifier">o</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">o</span> <span class="ruby-operator">&lt;=</span> <span class="ruby-constant">MAX_INTEGER_64</span>&#x000A; 68: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-operator">+</span> <span class="ruby-value str">&quot;L&quot;</span>&#x000A; 69: <span class="ruby-keyword kw">else</span>&#x000A; 70: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-operator">+</span> <span class="ruby-value str">&quot;BD&quot;</span>&#x000A; 71: <span class="ruby-keyword kw">end</span>&#x000A; 72: &#x000A; 73: <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Float</span>)&#x000A; 74: <span class="ruby-keyword kw">return</span> (<span class="ruby-identifier">o</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-operator">+</span> <span class="ruby-value str">&quot;F&quot;</span>)&#x000A; 75: &#x000A; 76: <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Rational</span>)&#x000A; 77: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">to_f</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-operator">+</span> <span class="ruby-value str">&quot;F&quot;</span>&#x000A; 78: &#x000A; 79: <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">BigDecimal</span>)&#x000A; 80: <span class="ruby-identifier">s</span> = <span class="ruby-identifier">o</span>.<span class="ruby-identifier">to_s</span>(<span class="ruby-value str">'F'</span>)&#x000A; 81: <span class="ruby-identifier">s</span>.<span class="ruby-identifier">sub!</span>(<span class="ruby-regexp re">/\.0$/</span>, <span class="ruby-value str">&quot;&quot;</span>)&#x000A; 82: <span class="ruby-keyword kw">return</span> <span class="ruby-node">&quot;#{s}BD&quot;</span>&#x000A; 83: &#x000A; 84: <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">nil?</span>&#x000A; 85: <span class="ruby-keyword kw">return</span> <span class="ruby-value str">&quot;null&quot;</span>&#x000A; 86: &#x000A; 87: <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">SdlBinary</span>)&#x000A; 88: <span class="ruby-identifier">encoded_o</span> = <span class="ruby-constant">Base64</span>.<span class="ruby-identifier">encode64</span>(<span class="ruby-identifier">o</span>.<span class="ruby-identifier">bytes</span>)&#x000A; 89: <span class="ruby-identifier">encoded_o</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-regexp re">/[\r\n]/</span><span class="ruby-identifier">m</span>, <span class="ruby-value str">&quot;&quot;</span>) <span class="ruby-comment cmt"># Remove the EOL inserted every 60 chars</span>&#x000A; 90: &#x000A; 91: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">add_quotes</span>&#x000A; 92: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">encoded_o</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">&gt;</span> <span class="ruby-constant">BASE64_WRAP_LINE_LENGTH</span>&#x000A; 93: <span class="ruby-comment cmt"># FIXME: we should a constant or some parameter instead of hardcoded spaces</span>&#x000A; 94: <span class="ruby-identifier">wrap_lines_in_ascii</span>(<span class="ruby-identifier">encoded_o</span>, <span class="ruby-constant">BASE64_WRAP_LINE_LENGTH</span>, <span class="ruby-node">&quot;#{line_prefix}#{indent}&quot;</span>)&#x000A; 95: <span class="ruby-identifier">encoded_o</span>.<span class="ruby-identifier">insert</span>(<span class="ruby-value">0</span>, <span class="ruby-node">&quot;[#{$/}&quot;</span>)&#x000A; 96: <span class="ruby-identifier">encoded_o</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;#{$/}#{line_prefix}]&quot;</span>&#x000A; 97: <span class="ruby-keyword kw">else</span>&#x000A; 98: <span class="ruby-identifier">encoded_o</span>.<span class="ruby-identifier">insert</span>(<span class="ruby-value">0</span>, <span class="ruby-value str">&quot;[&quot;</span>)&#x000A; 99: <span class="ruby-identifier">encoded_o</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">&quot;]&quot;</span>&#x000A;100: <span class="ruby-keyword kw">end</span>&#x000A;101: <span class="ruby-keyword kw">end</span>&#x000A;102: &#x000A;103: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">encoded_o</span>&#x000A;104: &#x000A;105: <span class="ruby-comment cmt"># Below, we use &quot;#{o.year}&quot; instead of &quot;%Y&quot; because &quot;%Y&quot; always emit 4 chars at least even if</span>&#x000A;106: <span class="ruby-comment cmt"># the date is before 1000.</span>&#x000A;107: <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">DateTime</span>) <span class="ruby-operator">||</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Time</span>)&#x000A;108: <span class="ruby-identifier">milliseconds</span> = <span class="ruby-identifier">get_datetime_milliseconds</span>(<span class="ruby-identifier">o</span>)&#x000A;109: &#x000A;110: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">milliseconds</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>&#x000A;111: <span class="ruby-identifier">zone_part</span> = <span class="ruby-identifier">o</span>.<span class="ruby-identifier">strftime</span>(<span class="ruby-value str">&quot;%:z&quot;</span>)&#x000A;112: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">zone_part</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">zone_part</span> <span class="ruby-operator">!=</span> <span class="ruby-value str">&quot;+00:00&quot;</span>&#x000A;113: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">strftime</span>(<span class="ruby-node">&quot;#{o.year}/%m/%d %H:%M:%S#{zone_part}&quot;</span>)&#x000A;114: <span class="ruby-keyword kw">else</span>&#x000A;115: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">strftime</span>(<span class="ruby-node">&quot;#{o.year}/%m/%d %H:%M:%S&quot;</span>)&#x000A;116: <span class="ruby-keyword kw">end</span>&#x000A;117: <span class="ruby-keyword kw">else</span>&#x000A;118: <span class="ruby-identifier">ms_part</span> = <span class="ruby-identifier">milliseconds</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">ljust</span>(<span class="ruby-value">3</span>, <span class="ruby-value str">'0'</span>)&#x000A;119: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">zone_part</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">zone_part</span> <span class="ruby-operator">!=</span> <span class="ruby-value str">&quot;+00:00&quot;</span>&#x000A;120: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">strftime</span>(<span class="ruby-node">&quot;#{o.year}/%m/%d %H:%M:%S.&quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">ms_part</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">zone_part</span>)&#x000A;121: <span class="ruby-keyword kw">else</span>&#x000A;122: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">strftime</span>(<span class="ruby-node">&quot;#{o.year}/%m/%d %H:%M:%S.&quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">ms_part</span>)&#x000A;123: <span class="ruby-keyword kw">end</span>&#x000A;124: <span class="ruby-keyword kw">end</span>&#x000A;125: &#x000A;126: <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Date</span>)&#x000A;127: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">strftime</span>(<span class="ruby-node">&quot;#{o.year}/%m/%d&quot;</span>)&#x000A;128: &#x000A;129: <span class="ruby-keyword kw">else</span>&#x000A;130: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">to_s</span>&#x000A;131: <span class="ruby-keyword kw">end</span>&#x000A;132: <span class="ruby-keyword kw">end</span></pre>
253
- </div>
254
- </div>
255
- <div class='method public-class' id='method-M000003'>
256
- <a name='M000003'></a>
257
- <div class='synopsis'>
258
- <span class='name'>new_date_time</span>
259
- <span class='arguments'>(year, month, day, hour, min, sec, time_zone_offset)</span>
260
- </div>
261
- <div class='description'>
262
- <p>
263
- Creates and returns the object representing a datetime (DateTime in the
264
- default implementation). This method is, by default, called by the <a
265
- href="SDL4R/Parser.html">Parser</a> class. It could be overriden as follows
266
- in order to get Time instances from all the <a href="SDL4R.html">SDL4R</a>
267
- parsers.
268
- </p>
269
- <pre>module SDL4R&#x000A; def self.new_date_time(year, month, day, hour, min, sec, time_zone_offset)&#x000A; Time.utc(year, month, day, hour, min, sec)&#x000A; end&#x000A;end</pre>
270
- </div>
271
- <div class='source'>
272
- <a class='source-toggle' href='#' onclick="toggleCode('M000003-source'); return false">
273
- [show source]
274
- </a>
275
- <pre id='M000003-source'> <span class="ruby-comment cmt"># File lib/sdl4r/sdl4r.rb, line 144</span>&#x000A;144: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">new_date_time</span>(<span class="ruby-identifier">year</span>, <span class="ruby-identifier">month</span>, <span class="ruby-identifier">day</span>, <span class="ruby-identifier">hour</span>, <span class="ruby-identifier">min</span>, <span class="ruby-identifier">sec</span>, <span class="ruby-identifier">time_zone_offset</span>)&#x000A;145: <span class="ruby-constant">DateTime</span>.<span class="ruby-identifier">civil</span>(<span class="ruby-identifier">year</span>, <span class="ruby-identifier">month</span>, <span class="ruby-identifier">day</span>, <span class="ruby-identifier">hour</span>, <span class="ruby-identifier">min</span>, <span class="ruby-identifier">sec</span>, <span class="ruby-identifier">time_zone_offset</span>)&#x000A;146: <span class="ruby-keyword kw">end</span></pre>
276
- </div>
277
- </div>
278
- <div class='method public-class' id='method-M000006'>
279
- <a name='M000006'></a>
280
- <div class='synopsis'>
281
- <span class='name'>read</span>
282
- <span class='arguments'>(input)</span>
283
- </div>
284
- <div class='description'>
285
- <p>
286
- Creates and returns a tag named &#8220;root&#8221; and add all the tags
287
- specified in the given <tt>input</tt>.
288
- </p>
289
- <table>
290
- <tr><td valign="top"><tt>input</tt>:</td><td>String, IO, Pathname or URI.
291
-
292
- </td></tr>
293
- </table>
294
- <pre>root = SDL4R::read(&lt;&lt;EOF&#x000A;planets {&#x000A; earth area_km2=510900000&#x000A; mars&#x000A;}&#x000A;EOF&#x000A;)&#x000A;&#x000A;root = SDL4R::read(Pathname.new(&quot;my_dir/my_file.sdl&quot;))&#x000A;&#x000A;IO.open(&quot;my_dir/my_file.sdl&quot;, &quot;r&quot;) { |io|&#x000A; root = SDL4R::read(io)&#x000A;}&#x000A;&#x000A;root = SDL4R::read(URI.new(&quot;http://my_site/my_file.sdl&quot;))</pre>
295
- </div>
296
- <div class='source'>
297
- <a class='source-toggle' href='#' onclick="toggleCode('M000006-source'); return false">
298
- [show source]
299
- </a>
300
- <pre id='M000006-source'> <span class="ruby-comment cmt"># File lib/sdl4r/sdl4r.rb, line 237</span>&#x000A;237: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">input</span>)&#x000A;238: <span class="ruby-constant">Tag</span>.<span class="ruby-identifier">new</span>(<span class="ruby-constant">ROOT_TAG_NAME</span>).<span class="ruby-identifier">read</span>(<span class="ruby-identifier">input</span>)&#x000A;239: <span class="ruby-keyword kw">end</span></pre>
301
- </div>
302
- </div>
303
- <div class='method public-class' id='method-M000009'>
304
- <a name='M000009'></a>
305
- <div class='synopsis'>
306
- <span class='name'>to_attribute_map</span>
307
- <span class='arguments'>(s)</span>
308
- </div>
309
- <div class='description'>
310
- <p>
311
- Parse a string representing the attributes portion of an SDL tag and return
312
- the results as a map.
313
- </p>
314
- <p>
315
- Example
316
- </p>
317
- <pre>hash = SDL4R.to_attribute_hash(&quot;value=1 debugging=on time=12:24:01&quot;);&#x000A;&#x000A;# { &quot;value&quot; =&gt; 1, &quot;debugging&quot; =&gt; true, &quot;time&quot; =&gt; SdlTimeSpan.new(12, 24, 01) }</pre>
318
- </div>
319
- <div class='source'>
320
- <a class='source-toggle' href='#' onclick="toggleCode('M000009-source'); return false">
321
- [show source]
322
- </a>
323
- <pre id='M000009-source'> <span class="ruby-comment cmt"># File lib/sdl4r/sdl4r.rb, line 275</span>&#x000A;275: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">to_attribute_map</span>(<span class="ruby-identifier">s</span>)&#x000A;276: <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">&quot;'s' cannot be null&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">nil?</span>&#x000A;277: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">read</span>(<span class="ruby-value str">&quot;atts &quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">s</span>).<span class="ruby-identifier">child</span>.<span class="ruby-identifier">attributes</span>&#x000A;278: <span class="ruby-keyword kw">end</span></pre>
324
- </div>
325
- </div>
326
- <div class='method public-class' id='method-M000007'>
327
- <a name='M000007'></a>
328
- <div class='synopsis'>
329
- <span class='name'>to_value</span>
330
- <span class='arguments'>(s)</span>
331
- </div>
332
- <div class='description'>
333
- <p>
334
- Parses and returns the value corresponding with the specified SDL literal.
335
- </p>
336
- <pre>SDL4R.to_value(&quot;\&quot;abcd\&quot;&quot;) # =&gt; &quot;abcd&quot;&#x000A;SDL4R.to_value(&quot;1&quot;) # =&gt; 1&#x000A;SDL4R.to_value(&quot;null&quot;) # =&gt; nil</pre>
337
- </div>
338
- <div class='source'>
339
- <a class='source-toggle' href='#' onclick="toggleCode('M000007-source'); return false">
340
- [show source]
341
- </a>
342
- <pre id='M000007-source'> <span class="ruby-comment cmt"># File lib/sdl4r/sdl4r.rb, line 247</span>&#x000A;247: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">to_value</span>(<span class="ruby-identifier">s</span>)&#x000A;248: <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">&quot;'s' cannot be null&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">nil?</span>&#x000A;249: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">read</span>(<span class="ruby-identifier">s</span>).<span class="ruby-identifier">child</span>.<span class="ruby-identifier">value</span>&#x000A;250: <span class="ruby-keyword kw">end</span></pre>
343
- </div>
344
- </div>
345
- <div class='method public-class' id='method-M000008'>
346
- <a name='M000008'></a>
347
- <div class='synopsis'>
348
- <span class='name'>to_value_array</span>
349
- <span class='arguments'>(s)</span>
350
- </div>
351
- <div class='description'>
352
- <p>
353
- Parse the string of values and return a list. The string is handled as if
354
- it is the values portion of an SDL tag.
355
- </p>
356
- <p>
357
- Example
358
- </p>
359
- <pre>array = SDL4R.to_value_array(&quot;1 true 12:24:01&quot;)</pre>
360
- <p>
361
- Will return an int, a boolean, and a time span.
362
- </p>
363
- </div>
364
- <div class='source'>
365
- <a class='source-toggle' href='#' onclick="toggleCode('M000008-source'); return false">
366
- [show source]
367
- </a>
368
- <pre id='M000008-source'> <span class="ruby-comment cmt"># File lib/sdl4r/sdl4r.rb, line 261</span>&#x000A;261: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">to_value_array</span>(<span class="ruby-identifier">s</span>)&#x000A;262: <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">&quot;'s' cannot be null&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">nil?</span>&#x000A;263: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">read</span>(<span class="ruby-identifier">s</span>).<span class="ruby-identifier">child</span>.<span class="ruby-identifier">values</span>&#x000A;264: <span class="ruby-keyword kw">end</span></pre>
369
- </div>
370
- </div>
371
- <div class='method public-class' id='method-M000005'>
372
- <a name='M000005'></a>
373
- <div class='synopsis'>
374
- <span class='name'>validate_identifier</span>
375
- <span class='arguments'>(identifier)</span>
376
- </div>
377
- <div class='description'>
378
- <p>
379
- Validates an SDL identifier String. SDL Identifiers must start with a
380
- Unicode letter or underscore (_) and contain only unicode letters, digits,
381
- underscores (_), dashes(-), periods (.) and dollar signs ($).
382
- </p>
383
- <h2>Raises</h2>
384
- <p>
385
- ArgumentError if the identifier is not legal
386
- </p>
387
- <p>
388
- TODO: support UTF-8 identifiers
389
- </p>
390
- </div>
391
- <div class='source'>
392
- <a class='source-toggle' href='#' onclick="toggleCode('M000005-source'); return false">
393
- [show source]
394
- </a>
395
- <pre id='M000005-source'> <span class="ruby-comment cmt"># File lib/sdl4r/sdl4r.rb, line 189</span>&#x000A;189: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">validate_identifier</span>(<span class="ruby-identifier">identifier</span>)&#x000A;190: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">identifier</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">identifier</span>.<span class="ruby-identifier">empty?</span>&#x000A;191: <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">&quot;SDL identifiers cannot be null or empty.&quot;</span>&#x000A;192: <span class="ruby-keyword kw">end</span>&#x000A;193: &#x000A;194: <span class="ruby-comment cmt"># in Java, was if(!Character.isJavaIdentifierStart(identifier.charAt(0)))</span>&#x000A;195: <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">identifier</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/^[a-zA-Z_]/</span>&#x000A;196: <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>,&#x000A;197: <span class="ruby-value str">&quot;'&quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">identifier</span>[<span class="ruby-value">0</span><span class="ruby-operator">..</span><span class="ruby-value">0</span>] <span class="ruby-operator">+</span>&#x000A;198: <span class="ruby-value str">&quot;' is not a legal first character for an SDL identifier. &quot;</span> <span class="ruby-operator">+</span>&#x000A;199: <span class="ruby-value str">&quot;SDL Identifiers must start with a unicode letter or &quot;</span> <span class="ruby-operator">+</span>&#x000A;200: <span class="ruby-value str">&quot;an underscore (_).&quot;</span>&#x000A;201: <span class="ruby-keyword kw">end</span>&#x000A;202: &#x000A;203: <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">identifier</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">==</span> <span class="ruby-value">1</span> <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">identifier</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/^[a-zA-Z_][a-zA-Z_0-9\-\.\$]*$/</span>&#x000A;204: <span class="ruby-keyword kw">for</span> <span class="ruby-identifier">i</span> <span class="ruby-keyword kw">in</span> <span class="ruby-value">1</span><span class="ruby-operator">..</span><span class="ruby-identifier">identifier</span>.<span class="ruby-identifier">length</span>&#x000A;205: <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">identifier</span>[<span class="ruby-identifier">i</span><span class="ruby-operator">..</span><span class="ruby-identifier">i</span>] <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/^[a-zA-Z_0-9\-\.\$]$/</span>&#x000A;206: <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>,&#x000A;207: <span class="ruby-value str">&quot;'&quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">identifier</span>[<span class="ruby-identifier">i</span><span class="ruby-operator">..</span><span class="ruby-identifier">i</span>] <span class="ruby-operator">+</span> &#x000A;208: <span class="ruby-value str">&quot;' is not a legal character for an SDL identifier. &quot;</span> <span class="ruby-operator">+</span>&#x000A;209: <span class="ruby-value str">&quot;SDL Identifiers must start with a unicode letter or &quot;</span> <span class="ruby-operator">+</span>&#x000A;210: <span class="ruby-value str">&quot;underscore (_) followed by 0 or more unicode &quot;</span> <span class="ruby-operator">+</span>&#x000A;211: <span class="ruby-value str">&quot;letters, digits, underscores (_), dashes (-), periodss (.) and dollar signs ($)&quot;</span>&#x000A;212: <span class="ruby-keyword kw">end</span>&#x000A;213: <span class="ruby-keyword kw">end</span>&#x000A;214: <span class="ruby-keyword kw">end</span>&#x000A;215: <span class="ruby-keyword kw">end</span></pre>
396
- </div>
397
- </div>
398
- </div>
399
- </div>
400
- </div>
401
- </div>
402
- <div id='footer-push'></div>
403
- </div>
404
- <div id='footer'>
405
- <a href="http://github.com/mislav/hanna/tree/master"><strong>Hanna</strong> RDoc template</a>
406
- </div>
407
- </body>
408
- </html>