Class: Masterplan::Document

Inherits:
Hash
  • Object
show all
Defined in:
lib/masterplan/document.rb

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}) ⇒ Document

Returns a new instance of Document.

Raises:

  • (ArgumentError)


4
5
6
7
8
9
# File 'lib/masterplan/document.rb', line 4

def initialize(hash = {})
  raise ArgumentError, "Can only work with a Hash, not a #{hash.class.name} !" unless hash.is_a?(Hash)
  hash.each do |k, v|
    self[k] = v
  end
end

Instance Method Details

#to_hashObject

Turns a Masterplan::Document into a plain Hash - this removes all special objects like Masterplan::Rule and replaces them with their example values, so the result can be used as documentation.



14
15
16
17
18
19
20
# File 'lib/masterplan/document.rb', line 14

def to_hash
  result = {}
  each do |k, v|
    result[self.class.derulerize(k)] = self.class.derulerize(v)
  end
  result
end