Module: IMW::Metadata::HasMetadata
- Included in:
- Schemes::Local::LocalFile
- Defined in:
- lib/imw/metadata/has_metadata.rb
Overview
A module which defines how a resource finds Metadata that it can look up metadata about itself.
“metadata” in this context is defined as accessors for metadata (IMW::Metadata), schema (IMW::Metadata::Schema), fields (IMW::Metadata::Field), and description (String).
An including class should define a method dir which should return an object that might contain Metadata, i.e. - that includes the IMW::Metadata::ContainsMetadata module.
An including class can optionally define the methods snippet which returns a snippet of the resource as well as record_count to return a count of how many records the resource contains.
Instance Method Summary collapse
-
#description ⇒ String
A description for this Resource.
-
#description=(new_description) ⇒ String
Set the description of this Resource.
-
#fields ⇒ Array<Hash>
The fields for this resource’s data.
-
#fields=(new_fields) ⇒ Array<Hash>
Set the fields for this resource.
-
#metadata ⇒ IMW::Metadata?
Return the metadata object that contains metadata for this resource.
-
#schema ⇒ Hash
The schema for this object.
Instance Method Details
#description ⇒ String
A description for this Resource.
78 79 80 |
# File 'lib/imw/metadata/has_metadata.rb', line 78 def description @description ||= && .description_for(self) end |
#description=(new_description) ⇒ String
Set the description of this Resource.
86 87 88 |
# File 'lib/imw/metadata/has_metadata.rb', line 86 def description= new_description @description = new_description end |
#fields ⇒ Array<Hash>
The fields for this resource’s data.
Each field will be a Hash of information.
63 64 65 |
# File 'lib/imw/metadata/has_metadata.rb', line 63 def fields @fields ||= && .fields_for(self) end |
#fields=(new_fields) ⇒ Array<Hash>
Set the fields for this resource.
71 72 73 |
# File 'lib/imw/metadata/has_metadata.rb', line 71 def fields= new_fields @fields = new_fields.map { |f| Metadata::Field.new(f) } end |
#metadata ⇒ IMW::Metadata?
Return the metadata object that contains metadata for this resource.
Will look in this resource’s directory and recursively upward till the root directory is reached or a metadata file is discovered.
48 49 50 51 52 53 54 55 56 |
# File 'lib/imw/metadata/has_metadata.rb', line 48 def return @metadata if @metadata d = dir while d.path != '/' break if d. && d..describes?(self) d = d.dir end @metadata = d. end |
#schema ⇒ Hash
The schema for this object.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/imw/metadata/has_metadata.rb', line 25 def schema return @schema if @schema @schema = IMW::Metadata::Schema.new @schema[:type] = "record" @schema[:namespace] = "schema.imw.resource" @schema[:name] = (basename || '') @schema[:doc] = description @schema[:fields] = fields @schema[:non_avro ] = {} @schema[:non_avro][:snippet] = snippet if respond_to?(:snippet) @schema[:non_avro][:record_count] = record_count if respond_to?(:record_count) @schema end |