Class: RDF::Format Abstract
- Inherits:
-
Object
- Object
- RDF::Format
- Extended by:
- Enumerable
- Defined in:
- lib/rdf/format.rb
Overview
The base class for RDF serialization formats.
Direct Known Subclasses
Class Method Summary (collapse)
-
+ content_encoding(encoding)
protected
Defines the content encoding for this RDF serialization format.
-
+ (Object) content_type(type = nil, options = {})
Retrieves or defines MIME content types for this RDF serialization format.
-
+ (Hash{String => Array<Class>}) content_types
Returns MIME content types for known RDF serialization formats.
-
+ (Enumerator) each {|klass| ... }
Enumerates known RDF serialization format classes.
-
+ (Hash{Symbol => String}) file_extensions
Returns file extensions for known RDF serialization formats.
-
+ (Class) for(options = {})
Finds an RDF serialization format class based on the given criteria.
-
+ reader(klass = nil, &block)
(also: reader_class)
Retrieves or defines the reader class for this RDF serialization format.
-
+ require(library)
protected
Defines a required Ruby library for this RDF serialization format.
-
+ writer(klass = nil, &block)
(also: writer_class)
Retrieves or defines the writer class for this RDF serialization format.
Class Method Details
+ content_encoding(encoding) (protected)
This method returns an undefined value.
Defines the content encoding for this RDF serialization format.
298 299 300 |
# File 'lib/rdf/format.rb', line 298 def self.content_encoding(encoding) @@content_encoding[self] = encoding.to_sym end |
+ content_type(type, options) + (Array<String>) content_type
Retrieves or defines MIME content types for this RDF serialization format.
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
# File 'lib/rdf/format.rb', line 260 def self.content_type(type = nil, = {}) if type.nil? [@@content_type[self], @@content_types.map { |ct, cl| (cl.include?(self) && ct != @@content_type[self]) ? ct : nil }].flatten.compact else @@content_type[self] = type (@@content_types[type] ||= []) << self if extensions = ([:extension] || [:extensions]) extensions = [extensions].flatten.map(&:to_sym) extensions.each { |ext| @@file_extensions[ext] = type } end if aliases = ([:alias] || [:aliases]) aliases = [aliases].flatten.each { |a| (@@content_types[a] ||= []) << self } end end end |
+ (Hash{String => Array<Class>}) content_types
Returns MIME content types for known RDF serialization formats.
130 131 132 |
# File 'lib/rdf/format.rb', line 130 def self.content_types @@content_types end |
+ (Enumerator) each {|klass| ... }
Enumerates known RDF serialization format classes.
54 55 56 |
# File 'lib/rdf/format.rb', line 54 def self.each(&block) @@subclasses.each(&block) end |
+ (Hash{Symbol => String}) file_extensions
Returns file extensions for known RDF serialization formats.
138 139 140 |
# File 'lib/rdf/format.rb', line 138 def self.file_extensions @@file_extensions end |
+ (Class) for(format) + (Class) for(filename) + (Class) for(options = {})
Finds an RDF serialization format class based on the given criteria.
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/rdf/format.rb', line 83 def self.for( = {}) case when String # Find a format based on the file name self.for(:file_name => ) when Hash case # Find a format based on the MIME content type: when mime_type = [:content_type] # @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17 # @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.7 mime_type = mime_type.to_s mime_type = mime_type.split(';').first if mime_type.include?(?;) # remove any media type parameters content_types.has_key?(mime_type) ? content_types[mime_type].first : nil # Find a format based on the file name: when file_name = [:file_name] self.for(:file_extension => File.extname(file_name.to_s)[1..-1]) # Find a format based on the file extension: when file_ext = [:file_extension] if file_extensions.has_key?(file_ext = file_ext.to_sym) self.for(:content_type => file_extensions[file_ext]) end end when Symbol case format = # Special case, since we want this to work despite autoloading when :ntriples RDF::NTriples::Format # For anything else, find a match based on the full class name else format = format.to_s.downcase @@subclasses.each do |klass| if klass.name.to_s.split('::').map(&:downcase).include?(format) return klass end end nil # not found end end end |
+ reader(klass) + reader { ... } + (Class) reader Also known as: reader_class
This method returns an undefined value.
Retrieves or defines the reader class for this RDF serialization format.
172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/rdf/format.rb', line 172 def self.reader(klass = nil, &block) case when klass @@readers[self] = klass when block_given? @@readers[self] = block else klass = @@readers[self] klass = @@readers[self] = klass.call if klass.is_a?(Proc) klass end end |
+ require(library) (protected)
This method returns an undefined value.
Defines a required Ruby library for this RDF serialization format.
The given library will be required lazily, i.e. only when it is actually first needed, such as when instantiating a reader or parser instance for this format.
289 290 291 |
# File 'lib/rdf/format.rb', line 289 def self.require(library) (@@requires[self] ||= []) << library.to_s end |
+ writer(klass) + writer { ... } + (Class) writer Also known as: writer_class
This method returns an undefined value.
Retrieves or defines the writer class for this RDF serialization format.
215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/rdf/format.rb', line 215 def self.writer(klass = nil, &block) case when klass @@writers[self] = klass when block_given? @@writers[self] = block else klass = @@writers[self] klass = @@writers[self] = klass.call if klass.is_a?(Proc) klass end end |