sdl4r 0.9.8 → 0.9.9
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +14 -1
- data/README +4 -4
- data/Rakefile +15 -12
- data/TODO +11 -4
- data/lib/sdl4r/parser.rb +25 -33
- data/lib/sdl4r/parser/token.rb +1 -1
- data/lib/sdl4r/sdl4r.rb +50 -22
- data/lib/sdl4r/sdl_time_span.rb +2 -2
- data/lib/sdl4r/serializer.rb +152 -0
- data/lib/sdl4r/tag.rb +15 -1
- data/test/sdl4r/parser_test.rb +5 -0
- data/test/sdl4r/serializer_test.rb +78 -0
- data/test/sdl4r/tag_test.rb +20 -1
- metadata +52 -81
- data/doc/classes/SDL4R.html +0 -408
- data/doc/classes/SDL4R/Parser.html +0 -190
- data/doc/classes/SDL4R/ParserTest.html +0 -385
- data/doc/classes/SDL4R/SDL4RTest.html +0 -532
- data/doc/classes/SDL4R/SDLTest.html +0 -77
- data/doc/classes/SDL4R/SdlBinary.html +0 -188
- data/doc/classes/SDL4R/SdlParseError.html +0 -110
- data/doc/classes/SDL4R/SdlTimeSpan.html +0 -637
- data/doc/classes/SDL4R/Tag.html +0 -1249
- data/doc/classes/SDL4R/TagTest.html +0 -292
- data/doc/created.rid +0 -1
- data/doc/files/CHANGELOG.html +0 -200
- data/doc/files/LICENSE.html +0 -497
- data/doc/files/README.html +0 -406
- data/doc/files/lib/sdl4r/parser/reader_rb.html +0 -54
- data/doc/files/lib/sdl4r/parser/time_span_with_zone_rb.html +0 -54
- data/doc/files/lib/sdl4r/parser/token_rb.html +0 -54
- data/doc/files/lib/sdl4r/parser/tokenizer_rb.html +0 -54
- data/doc/files/lib/sdl4r/parser_rb.html +0 -62
- data/doc/files/lib/sdl4r/sdl4r_rb.html +0 -64
- data/doc/files/lib/sdl4r/sdl_binary_rb.html +0 -54
- data/doc/files/lib/sdl4r/sdl_parse_error_rb.html +0 -54
- data/doc/files/lib/sdl4r/sdl_time_span_rb.html +0 -54
- data/doc/files/lib/sdl4r/tag_rb.html +0 -64
- data/doc/files/lib/sdl4r_rb.html +0 -54
- data/doc/files/test/sdl4r/parser_test_rb.html +0 -64
- data/doc/files/test/sdl4r/sdl4r_test_rb.html +0 -67
- data/doc/files/test/sdl4r/sdl_test_rb.html +0 -64
- data/doc/files/test/sdl4r/tag_test_rb.html +0 -64
- data/doc/fr_class_index.html +0 -19
- data/doc/fr_file_index.html +0 -37
- data/doc/fr_method_index.html +0 -4711
- data/doc/index.html +0 -15
- data/doc/rdoc-style.css +0 -328
data/lib/sdl4r/tag.rb
CHANGED
@@ -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
|
-
|
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
|
data/test/sdl4r/parser_test.rb
CHANGED
@@ -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
|
data/test/sdl4r/tag_test.rb
CHANGED
@@ -622,6 +622,25 @@ EOF
|
|
622
622
|
output)
|
623
623
|
end
|
624
624
|
|
625
|
-
|
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
|
-
|
7
|
-
|
8
|
-
|
9
|
-
version: 0.9.
|
6
|
+
- 0
|
7
|
+
- 9
|
8
|
+
- 9
|
9
|
+
version: 0.9.9
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
|
-
|
13
|
-
|
12
|
+
- Philippe Vosges
|
13
|
+
- Daniel Leuck
|
14
14
|
autorequire:
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
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
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
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://
|
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
|
-
|
63
|
+
- lib
|
96
64
|
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
97
66
|
requirements:
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
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
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
segments:
|
78
|
+
- 0
|
79
|
+
version: "0"
|
110
80
|
requirements:
|
111
|
-
|
81
|
+
- none
|
112
82
|
rubyforge_project: sdl4r
|
113
|
-
rubygems_version: 1.3.
|
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
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
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
|
data/doc/classes/SDL4R.html
DELETED
@@ -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>),’../../lib’) if
|
90
|
-
ENV[“NB_EXEC_EXTEXECUTION_PROCESS_UUID“]
|
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'>"content"</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'>"root"</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'>{ "\"" => "\\\"", "'" => "\\'", "`" => "\\`", }</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'>{ "\\" => "\\\\", "\t" => "\\t", "\r" => "\\r", "\n" => "\\n", }</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 ‘o’ 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>
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>)
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>
74: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">o</span>
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>
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>)
77: <span class="ruby-keyword kw">else</span>
78: <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">"can't coerce argument"</span>
79: <span class="ruby-keyword kw">end</span>
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>
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>)
157: <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">o</span>
158: 
159: <span class="ruby-keyword kw">when</span> <span class="ruby-constant">Rational</span>
160: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">to_f</span>
161: 
162: <span class="ruby-keyword kw">when</span> <span class="ruby-constant">NilClass</span>,
163: <span class="ruby-constant">String</span>,
164: <span class="ruby-constant">Numeric</span>,
165: <span class="ruby-constant">Float</span>,
166: <span class="ruby-constant">TrueClass</span>,
167: <span class="ruby-constant">FalseClass</span>,
168: <span class="ruby-constant">Date</span>,
169: <span class="ruby-constant">DateTime</span>,
170: <span class="ruby-constant">Time</span>,
171: <span class="ruby-constant">SdlTimeSpan</span>,
172: <span class="ruby-constant">SdlBinary</span>
173: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">o</span>
174: 
175: <span class="ruby-keyword kw">end</span>
176: 
177: <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">"#{o.class.name} is not coercible to an SDL type"</span>
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 = "", indent = "\t")</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 (“” by default)
|
241
|
-
|
242
|
-
</td></tr>
|
243
|
-
<tr><td valign="top"><tt>indent</tt>:</td><td>the indent string to use (“t“ 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>
 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">""</span>, <span class="ruby-identifier">indent</span> = <span class="ruby-value str">"\t"</span>)
 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>)
 49: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">add_quotes</span>
 50: <span class="ruby-identifier">o_length</span> = <span class="ruby-value">0</span>
 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>
 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>
 53: <span class="ruby-keyword kw">return</span> <span class="ruby-value str">"'"</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">escape</span>(<span class="ruby-identifier">o</span>, <span class="ruby-value str">"'"</span>) <span class="ruby-operator">+</span> <span class="ruby-value str">"'"</span>
 54: <span class="ruby-keyword kw">else</span>
 55: <span class="ruby-keyword kw">return</span> <span class="ruby-value str">'"'</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">escape</span>(<span class="ruby-identifier">o</span>, <span class="ruby-value str">'"'</span>) <span class="ruby-operator">+</span> <span class="ruby-value str">'"'</span>
 56: <span class="ruby-keyword kw">end</span>
 57: <span class="ruby-keyword kw">else</span>
 58: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">escape</span>(<span class="ruby-identifier">o</span>)
 59: <span class="ruby-keyword kw">end</span>
 60: 
 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>)
 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">"BD"</span>
 63: 
 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>)
 65: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">MIN_INTEGER_32</span> <span class="ruby-operator"><=</span> <span class="ruby-identifier">o</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">o</span> <span class="ruby-operator"><=</span> <span class="ruby-constant">MAX_INTEGER_32</span>
 66: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">to_s</span>
 67: <span class="ruby-keyword kw">elsif</span> <span class="ruby-constant">MIN_INTEGER_64</span> <span class="ruby-operator"><=</span> <span class="ruby-identifier">o</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">o</span> <span class="ruby-operator"><=</span> <span class="ruby-constant">MAX_INTEGER_64</span>
 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">"L"</span>
 69: <span class="ruby-keyword kw">else</span>
 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">"BD"</span>
 71: <span class="ruby-keyword kw">end</span>
 72: 
 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>)
 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">"F"</span>)
 75: 
 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>)
 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">"F"</span>
 78: 
 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>)
 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>)
 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">""</span>)
 82: <span class="ruby-keyword kw">return</span> <span class="ruby-node">"#{s}BD"</span>
 83: 
 84: <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">nil?</span>
 85: <span class="ruby-keyword kw">return</span> <span class="ruby-value str">"null"</span>
 86: 
 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>)
 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>)
 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">""</span>) <span class="ruby-comment cmt"># Remove the EOL inserted every 60 chars</span>
 90: 
 91: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">add_quotes</span>
 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">></span> <span class="ruby-constant">BASE64_WRAP_LINE_LENGTH</span>
 93: <span class="ruby-comment cmt"># FIXME: we should a constant or some parameter instead of hardcoded spaces</span>
 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">"#{line_prefix}#{indent}"</span>)
 95: <span class="ruby-identifier">encoded_o</span>.<span class="ruby-identifier">insert</span>(<span class="ruby-value">0</span>, <span class="ruby-node">"[#{$/}"</span>)
 96: <span class="ruby-identifier">encoded_o</span> <span class="ruby-operator"><<</span> <span class="ruby-node">"#{$/}#{line_prefix}]"</span>
 97: <span class="ruby-keyword kw">else</span>
 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">"["</span>)
 99: <span class="ruby-identifier">encoded_o</span> <span class="ruby-operator"><<</span> <span class="ruby-value str">"]"</span>
100: <span class="ruby-keyword kw">end</span>
101: <span class="ruby-keyword kw">end</span>
102: 
103: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">encoded_o</span>
104: 
105: <span class="ruby-comment cmt"># Below, we use "#{o.year}" instead of "%Y" because "%Y" always emit 4 chars at least even if</span>
106: <span class="ruby-comment cmt"># the date is before 1000.</span>
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>)
108: <span class="ruby-identifier">milliseconds</span> = <span class="ruby-identifier">get_datetime_milliseconds</span>(<span class="ruby-identifier">o</span>)
109: 
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>
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">"%:z"</span>)
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">"+00:00"</span>
113: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">strftime</span>(<span class="ruby-node">"#{o.year}/%m/%d %H:%M:%S#{zone_part}"</span>)
114: <span class="ruby-keyword kw">else</span>
115: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">strftime</span>(<span class="ruby-node">"#{o.year}/%m/%d %H:%M:%S"</span>)
116: <span class="ruby-keyword kw">end</span>
117: <span class="ruby-keyword kw">else</span>
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>)
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">"+00:00"</span>
120: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">strftime</span>(<span class="ruby-node">"#{o.year}/%m/%d %H:%M:%S."</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>)
121: <span class="ruby-keyword kw">else</span>
122: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">strftime</span>(<span class="ruby-node">"#{o.year}/%m/%d %H:%M:%S."</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">ms_part</span>)
123: <span class="ruby-keyword kw">end</span>
124: <span class="ruby-keyword kw">end</span>
125: 
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>)
127: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">strftime</span>(<span class="ruby-node">"#{o.year}/%m/%d"</span>)
128: 
129: <span class="ruby-keyword kw">else</span>
130: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">o</span>.<span class="ruby-identifier">to_s</span>
131: <span class="ruby-keyword kw">end</span>
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
 def self.new_date_time(year, month, day, hour, min, sec, time_zone_offset)
 Time.utc(year, month, day, hour, min, sec)
 end
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>
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>)
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>)
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 “root” 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(<<EOF
planets {
 earth area_km2=510900000
 mars
}
EOF
)

root = SDL4R::read(Pathname.new("my_dir/my_file.sdl"))

IO.open("my_dir/my_file.sdl", "r") { |io|
 root = SDL4R::read(io)
}

root = SDL4R::read(URI.new("http://my_site/my_file.sdl"))</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>
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>)
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>)
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("value=1 debugging=on time=12:24:01");

# { "value" => 1, "debugging" => true, "time" => 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>
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>)
276: <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">"'s' cannot be null"</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">nil?</span>
277: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">read</span>(<span class="ruby-value str">"atts "</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">s</span>).<span class="ruby-identifier">child</span>.<span class="ruby-identifier">attributes</span>
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("\"abcd\"") # => "abcd"
SDL4R.to_value("1") # => 1
SDL4R.to_value("null") # => 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>
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>)
248: <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">"'s' cannot be null"</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">nil?</span>
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>
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("1 true 12:24:01")</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>
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>)
262: <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">"'s' cannot be null"</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">nil?</span>
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>
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>
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>)
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>
191: <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">"SDL identifiers cannot be null or empty."</span>
192: <span class="ruby-keyword kw">end</span>
193: 
194: <span class="ruby-comment cmt"># in Java, was if(!Character.isJavaIdentifierStart(identifier.charAt(0)))</span>
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>
196: <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>,
197: <span class="ruby-value str">"'"</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>
198: <span class="ruby-value str">"' is not a legal first character for an SDL identifier. "</span> <span class="ruby-operator">+</span>
199: <span class="ruby-value str">"SDL Identifiers must start with a unicode letter or "</span> <span class="ruby-operator">+</span>
200: <span class="ruby-value str">"an underscore (_)."</span>
201: <span class="ruby-keyword kw">end</span>
202: 
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>
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>
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>
206: <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>,
207: <span class="ruby-value str">"'"</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> 
208: <span class="ruby-value str">"' is not a legal character for an SDL identifier. "</span> <span class="ruby-operator">+</span>
209: <span class="ruby-value str">"SDL Identifiers must start with a unicode letter or "</span> <span class="ruby-operator">+</span>
210: <span class="ruby-value str">"underscore (_) followed by 0 or more unicode "</span> <span class="ruby-operator">+</span>
211: <span class="ruby-value str">"letters, digits, underscores (_), dashes (-), periodss (.) and dollar signs ($)"</span>
212: <span class="ruby-keyword kw">end</span>
213: <span class="ruby-keyword kw">end</span>
214: <span class="ruby-keyword kw">end</span>
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>
|