class Masterplan::Document
Public Class Methods
new(hash = {})
click to toggle source
# 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
Private Class Methods
derulerize(object)
click to toggle source
# File lib/masterplan/document.rb, line 24 def self.derulerize(object) case object when Hash new(object).to_hash when Array object.map { |e| derulerize(e) } when Masterplan::Rule derulerize(object.example_value) else object end end
Public Instance Methods
to_hash()
click to toggle source
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.
# 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