Class: DataMetaDom::Documentable
- Inherits:
-
Object
- Object
- DataMetaDom::Documentable
- Defined in:
- lib/dataMetaDom/docs.rb
Overview
Anything that can have documentation.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#docs ⇒ Object
The hash keyed by the target.
Instance Method Summary collapse
-
#addDoc(doc) ⇒ Object
Adds the document by putting it into the underlying cache with the target key.
-
#all ⇒ Object
All the instances of the Doc stored on this instance.
-
#clear ⇒ Object
Reinitializes the instance with no docs.
-
#docConsumed?(source) ⇒ Boolean
Attempts to consume a Doc from the given source, returns true if succeeded.
-
#getDoc(key) ⇒ Object
Fetches the instance of Doc by the given key, the target.
-
#has?(key) ⇒ Boolean
Determines if the given document target is defined on this instance.
-
#ids ⇒ Object
All the ids, namely the targets of all the documents on this instance.
-
#initialize ⇒ Documentable
constructor
Initializes the instance with an empty hash.
Constructor Details
#initialize ⇒ Documentable
Initializes the instance with an empty hash.
82 |
# File 'lib/dataMetaDom/docs.rb', line 82 def initialize; @docs = {} end |
Instance Attribute Details
#docs ⇒ Object
The hash keyed by the target.
79 80 81 |
# File 'lib/dataMetaDom/docs.rb', line 79 def docs @docs end |
Instance Method Details
#addDoc(doc) ⇒ Object
Adds the document by putting it into the underlying cache with the target key.
88 89 90 |
# File 'lib/dataMetaDom/docs.rb', line 88 def addDoc(doc) @docs[doc.target] = doc end |
#all ⇒ Object
All the instances of the Doc stored on this instance.
96 |
# File 'lib/dataMetaDom/docs.rb', line 96 def all; @docs.values end |
#clear ⇒ Object
Reinitializes the instance with no docs.
108 |
# File 'lib/dataMetaDom/docs.rb', line 108 def clear; @docs[] = {} end |
#docConsumed?(source) ⇒ Boolean
Attempts to consume a Doc from the given source, returns true if succeeded.
-
Parameters:
-
source
- an instance of SourceFile -
target
- the target, the format of the Doc.
-
116 117 118 |
# File 'lib/dataMetaDom/docs.rb', line 116 def docConsumed?(source) source.line =~ /^\s*#{DOC}\s+(\w+)$/ ? addDoc(Doc.parse(source, [$1])) : nil end |
#getDoc(key) ⇒ Object
Fetches the instance of Doc by the given key, the target
85 |
# File 'lib/dataMetaDom/docs.rb', line 85 def getDoc(key); @docs[key] end |
#has?(key) ⇒ Boolean
Determines if the given document target is defined on this instance.
-
Parameter:
-
key
- the target.
-
103 |
# File 'lib/dataMetaDom/docs.rb', line 103 def has?(key) ; @docs.member?(key) end |
#ids ⇒ Object
All the ids, namely the targets of all the documents on this instance.
93 |
# File 'lib/dataMetaDom/docs.rb', line 93 def ids; @docs.keys end |