Class: DataMetaDom::Documentable

Inherits:
Object
  • Object
show all
Defined in:
lib/dataMetaDom/docs.rb

Overview

Anything that can have documentation.

Direct Known Subclasses

VerDoccable

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDocumentable

Initializes the instance with an empty hash.



82
# File 'lib/dataMetaDom/docs.rb', line 82

def initialize; @docs = {} end

Instance Attribute Details

#docsObject

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

#allObject

All the instances of the Doc stored on this instance.



96
# File 'lib/dataMetaDom/docs.rb', line 96

def all; @docs.values end

#clearObject

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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


103
# File 'lib/dataMetaDom/docs.rb', line 103

def has?(key) ; @docs.member?(key) end

#idsObject

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