Class: CSL::Schema
Class Attribute Summary collapse
-
.attributes ⇒ Object
Returns the value of attribute attributes.
-
.categories ⇒ Object
Returns the value of attribute categories.
-
.default_license ⇒ Object
Returns the value of attribute default_license.
-
.default_rights_string ⇒ Object
Returns the value of attribute default_rights_string.
-
.major_version ⇒ Object
Returns the value of attribute major_version.
-
.namespace ⇒ Object
Returns the value of attribute namespace.
-
.preamble ⇒ Object
Returns the value of attribute preamble.
-
.types ⇒ Object
Returns the value of attribute types.
-
.values ⇒ Object
Returns the value of attribute values.
-
.variables ⇒ Object
Returns the value of attribute variables.
-
.version ⇒ Object
Returns the value of attribute version.
Class Method Summary collapse
- .attr(*arguments) ⇒ Object
-
.valid?(style) ⇒ Boolean
Whether or not the passed-in style (or list of styles) is valid.
-
.validate(node) ⇒ <<Fixnum,String>>
Validates the passed-in style or list of styles.
Class Attribute Details
.attributes ⇒ Object
Returns the value of attribute attributes.
276 277 278 |
# File 'lib/csl/schema.rb', line 276 def attributes @attributes end |
.categories ⇒ Object
Returns the value of attribute categories.
276 277 278 |
# File 'lib/csl/schema.rb', line 276 def categories @categories end |
.default_license ⇒ Object
Returns the value of attribute default_license.
276 277 278 |
# File 'lib/csl/schema.rb', line 276 def default_license @default_license end |
.default_rights_string ⇒ Object
Returns the value of attribute default_rights_string.
276 277 278 |
# File 'lib/csl/schema.rb', line 276 def default_rights_string @default_rights_string end |
.major_version ⇒ Object
Returns the value of attribute major_version.
276 277 278 |
# File 'lib/csl/schema.rb', line 276 def major_version @major_version end |
.namespace ⇒ Object
Returns the value of attribute namespace.
276 277 278 |
# File 'lib/csl/schema.rb', line 276 def namespace @namespace end |
.preamble ⇒ Object
Returns the value of attribute preamble.
276 277 278 |
# File 'lib/csl/schema.rb', line 276 def preamble @preamble end |
.types ⇒ Object
Returns the value of attribute types.
276 277 278 |
# File 'lib/csl/schema.rb', line 276 def types @types end |
.values ⇒ Object
Returns the value of attribute values.
276 277 278 |
# File 'lib/csl/schema.rb', line 276 def values @values end |
.variables ⇒ Object
Returns the value of attribute variables.
276 277 278 |
# File 'lib/csl/schema.rb', line 276 def variables @variables end |
.version ⇒ Object
Returns the value of attribute version.
276 277 278 |
# File 'lib/csl/schema.rb', line 276 def version @version end |
Class Method Details
.attr(*arguments) ⇒ Object
282 283 284 |
# File 'lib/csl/schema.rb', line 282 def attr(*arguments) attributes.values_at(*arguments).flatten(1) end |
.valid?(style) ⇒ Boolean
Whether or not the passed-in style (or list of styles) is valid.
350 351 352 |
# File 'lib/csl/schema.rb', line 350 def valid?(style) validate(style).empty? end |
.validate(node) ⇒ <<Fixnum,String>>
Validates the passed-in style or list of styles. The style argument(s) can either be a CSL::Style object, a style’s file handle, XML content or a valid location (wildcards are supported). The method returns a list of validation errors; the passed-in style is valid if the method returns an empty list.
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 |
# File 'lib/csl/schema.rb', line 307 def validate(node) case when node.is_a?(Node) @validator[@schema, node.to_xml] when node.respond_to?(:read) @validator[@schema, node.read] when node.is_a?(Enumerable) && !node.is_a?(String) node.map { |n| validate(n) }.flatten(1) when node.respond_to?(:to_s) node = node.to_s case when node =~ /^\s*</ @validator[@schema, node] when File.exists?(node) @validator[@schema, File.open(node, 'r:UTF-8')] else glob = Dir.glob(node) if glob.empty? @validator[@schema, Kernel.open(node)] else glob.map { |n| @validator[@schema, File.open(n, 'r:UTF-8')] }.flatten(1) end end else raise ArgumentError, "failed to validate #{node.inspect}: not a CSL node" end end |