lib/sdl4r/sdl4r.rb in sdl4r-0.9.7 vs lib/sdl4r/sdl4r.rb in sdl4r-0.9.8
- old
+ new
@@ -32,10 +32,13 @@
MAX_INTEGER_64 = 2**63 - 1
MIN_INTEGER_64 = -(2**63)
BASE64_WRAP_LINE_LENGTH = 72
+ ANONYMOUS_TAG_NAME = "content"
+ ROOT_TAG_NAME = "root"
+
# Creates an SDL string representation for a given object and returns it.
#
# +o+:: the object to format
# +add_quotes+:: indicates whether quotes will be added to Strings and characters (true by default)
# +line_prefix+:: the line prefix to use ("" by default)
@@ -103,20 +106,22 @@
# the date is before 1000.
elsif o.is_a?(DateTime) || o.is_a?(Time)
milliseconds = get_datetime_milliseconds(o)
if milliseconds == 0
- if o.zone
- return o.strftime("#{o.year}/%m/%d %H:%M:%S%Z")
+ zone_part = o.strftime("%:z")
+ if zone_part and zone_part != "+00:00"
+ return o.strftime("#{o.year}/%m/%d %H:%M:%S#{zone_part}")
else
return o.strftime("#{o.year}/%m/%d %H:%M:%S")
end
else
- if o.zone
- return o.strftime("#{o.year}/%m/%d %H:%M:%S." + milliseconds.to_s.ljust(3, '0') + "%Z")
+ ms_part = milliseconds.to_s.ljust(3, '0')
+ if zone_part and zone_part != "+00:00"
+ return o.strftime("#{o.year}/%m/%d %H:%M:%S." + ms_part + zone_part)
else
- return o.strftime("#{o.year}/%m/%d %H:%M:%S." + milliseconds.to_s.ljust(3, '0'))
+ return o.strftime("#{o.year}/%m/%d %H:%M:%S." + ms_part)
end
end
elsif o.is_a?(Date)
return o.strftime("#{o.year}/%m/%d")
@@ -172,11 +177,11 @@
raise ArgumentError, "#{o.class.name} is not coercible to an SDL type"
end
# Validates an SDL identifier String. SDL Identifiers must start with a
# Unicode letter or underscore (_) and contain only unicode letters,
- # digits, underscores (_), dashes(-) and periods (.).
+ # digits, underscores (_), dashes(-), periods (.) and dollar signs ($).
#
# == Raises
# ArgumentError if the identifier is not legal
#
# TODO: support UTF-8 identifiers
@@ -193,19 +198,19 @@
"' is not a legal first character for an SDL identifier. " +
"SDL Identifiers must start with a unicode letter or " +
"an underscore (_)."
end
- unless identifier.length == 1 or identifier =~ /^[a-zA-Z_][a-zA-Z_0-9\-\.]*$/
+ unless identifier.length == 1 or identifier =~ /^[a-zA-Z_][a-zA-Z_0-9\-\.\$]*$/
for i in 1..identifier.length
- unless identifier[i..i] =~ /^[a-zA-Z_0-9\-]$/
+ unless identifier[i..i] =~ /^[a-zA-Z_0-9\-\.\$]$/
raise ArgumentError,
"'" + identifier[i..i] +
"' is not a legal character for an SDL identifier. " +
"SDL Identifiers must start with a unicode letter or " +
"underscore (_) followed by 0 or more unicode " +
- "letters, digits, underscores (_), or dashes (-)"
+ "letters, digits, underscores (_), dashes (-), periodss (.) and dollar signs ($)"
end
end
end
end
@@ -228,10 +233,10 @@
# }
#
# root = SDL4R::read(URI.new("http://my_site/my_file.sdl"))
#
def self.read(input)
- Tag.new("root").read(input)
+ Tag.new(ROOT_TAG_NAME).read(input)
end
# Parses and returns the value corresponding with the specified SDL literal.
#
# SDL4R.to_value("\"abcd\"") # => "abcd"
\ No newline at end of file