lib/csl/locale.rb in csl-1.0.0.pre1 vs lib/csl/locale.rb in csl-1.0.0.pre2
- old
+ new
@@ -35,21 +35,22 @@
attr_accessor :default
attr_reader :languages, :regions
def parse(data)
- node = CSL.parse!(data)
+ node = CSL.parse!(data, self)
raise ParseError, "root node is not a locale: #{node.inspect}" unless
node.is_a?(self)
node
end
end
attr_defaults :version => Schema.version, :xmlns => Schema.namespace
+ attr_struct :xmlns, :version
attr_children :'style-options', :info, :date, :terms
attr_accessor :language, :region
@@ -310,10 +311,18 @@
end
[number, ordinal.to_s(options)].join
end
+ def validate
+ Schema.validate self
+ end
+
+ def valid?
+ validate.empty?
+ end
+
# Locales are sorted first by language, then by region; sort order is
# alphabetical with the following exceptions: the default locale is
# prioritised; in case of a language match the default region of that
# language will be prioritised (e.g., de-DE will come before de-AT even
# though the alphabetical order would be different).
@@ -355,12 +364,20 @@
end
private
def attribute_assignments
- super.push('xml:lang="%s"' % to_s)
+ if root?
+ super.push('xml:lang="%s"' % to_s)
+ else
+ 'xml:lang="%s"' % to_s
+ end
end
+ def preamble
+ Schema.preamble.dup
+ end
+
# @return [Hash] a valid ordinalize query; the name attribute is a format string
def ordinalize_query_for(options)
q = { :name => 'ordinal-%02d' }
unless options.nil?
\ No newline at end of file