Class: ManaMana::RDSL::RequirementNode

Inherits:
NodeWithOffset show all
Defined in:
lib/manamana/rdsl/nodes.rb

Instance Attribute Summary

Attributes inherited from NodeWithOffset

#offset

Attributes inherited from Node

#children, #name

Instance Method Summary collapse

Methods inherited from NodeWithOffset

#==, #initialize

Methods inherited from Node

#==, #initialize

Constructor Details

This class inherits a constructor from ManaMana::RDSL::NodeWithOffset

Instance Method Details

#examplesObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/manamana/rdsl/nodes.rb', line 52

def examples
  # RowNodes initialized this way:
  # RowNode.new({ value: ['Role', 'Can or Cannot Create'], offset: XX }),
  # RowNode.new({ value: ['PM',   'Can Create'          ], offset: XX }),
  # RowNode.new({ value: ['User', 'Cannot Create'       ], offset: XX })

  # ...will be returned by this method this way:
  # [
  #   { '<Role>' => 'PM',   '<Can or Cannot Create>' => 'Can Create'    },
  #   { '<Role>' => 'User', '<Can or Cannot Create>' => 'Cannot Create' }
  # ]
  return [] if children.length == 0

  nodes   = children[0].rows
  headers = nodes[0].cells
  rows    = []

  nodes[1..-1].each do |node|
    row = {}
    node.cells.each_with_index do |value, index|
      row["<#{headers[index]}>"] = value
    end
    rows << row
  end

  rows
end

#expandObject



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/manamana/rdsl/nodes.rb', line 80

def expand
  return [name] if examples.length == 0

  requirements = []

  examples.each do |row|
    tmp = name.dup
    row.each_key do |key|
      tmp.gsub! key, row[key]
    end
    requirements << tmp
  end

  requirements
end