Module: Sanctuary::Planter::Parser

Defined in:
lib/sanctuary/planter/parser.rb

Class Method Summary collapse

Class Method Details

.generate_plant_data_objects(classes_array) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/sanctuary/planter/parser.rb', line 29

def self.generate_plant_data_objects(classes_array)
  classes_array.map do |klass|
    fields = []
    methods = []
    plant_template = klass[0].split(":")[1].chomp
    name = klass[1].split("class")[1].split(" ")[0].chomp
    klass[2..(klass.length - 2)].each do |line|
      if line.include?("()")
        methods << line.strip
      else
        fields << line.strip
      end
    end

    Sanctuary::Planter::Plant.new(name, fields, methods, plant_template)
  end
end

.parse_plant_uml(path) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/sanctuary/planter/parser.rb', line 6

def self.parse_plant_uml(path)
  classes = []
  File.open(path) do |file|
    reading = false
    lines_read = ""
    file.each do |line|
      if line.include?("TYPE")
        reading = true
      end
      if reading
        lines_read << line
      end
      if line.include?("}")
        reading = false
        classes << lines_read.split("\n")
        lines_read = ""
      end
    end
  end

  classes
end