Class: RailsClafer::ClaferPrinter

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_clafer/clafer_printer.rb

Class Method Summary collapse

Class Method Details

.build_whitespace(indent_level) ⇒ Object



39
40
41
# File 'lib/rails_clafer/clafer_printer.rb', line 39

def build_whitespace(indent_level)
  ' ' * indent_level * 4
end


31
32
33
34
35
36
37
# File 'lib/rails_clafer/clafer_printer.rb', line 31

def print_abstract(clafer)
  if clafer.is_abstract?
    "abstract "
  else 
    ""
  end
end


58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/rails_clafer/clafer_printer.rb', line 58

def print_card(card)
  map = {[1, 1]=>"",
         [0, 1] => "?",
         [1, "*"] => "+",
         [0, "*"] => "*" }
  out = map[[card.min, card.max]]
  out = "#{card.min}..#{card.max}" unless out != nil
  out
  #if card.min == 1 && card.max  == 1
  #  ""
  #elsif card.min == 0 && card.max = 1
  #  "?"
  #elsif card.min == 1 && card.max =="*"
  #  "+"
  #elsif card.min == 0 && card.max == "*"
  #  "*"
  #else
  #  "#{card.min}..#{card.max}"
  #end
end


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rails_clafer/clafer_printer.rb', line 12

def print_clafer(clafer, indent_level)
  whitespace =   build_whitespace(indent_level)
  out = whitespace
  if clafer.respond_to?(:ref_name)
    out << print_ref_clafer(clafer)
  elsif clafer.respond_to?(:name)
    out << print_reg_clafer(clafer)
  end
  out << "\n"
  if clafer.respond_to?(:children)
    subclafers = clafer.children
    subclafers.each do |subclafer|
      out << print_clafer(subclafer, indent_level + 1)
    end
  end
  out << print_constraint(indent_level + 1, clafer.constraint) unless clafer.constraint.blank?
  out

end


4
5
6
7
8
9
10
# File 'lib/rails_clafer/clafer_printer.rb', line 4

def print_clafers(list)
  out = ""
  list.each do |clafer|
    out << print_clafer(clafer, 0)
  end
  out 
end


43
44
45
46
47
48
# File 'lib/rails_clafer/clafer_printer.rb', line 43

def print_constraint(indent_level, constraint)
  out = build_whitespace(indent_level)
  out << constraint
  out << "\n"
  out
end


79
80
81
82
83
84
85
86
87
88
89
# File 'lib/rails_clafer/clafer_printer.rb', line 79

def print_gcard(gcard)
  map = {[0,"*"]=>"",
         [1, 1] => "xor",
         [1, "*"] => "or",
         [0, 1] => "mux" }
  #[0, "*"] => "opt" }
  out = map[[gcard.min, gcard.max]]
  out = "#{gcard.min}-#{gcard.max}" unless out != nil
  out << " " unless out.empty?
  out
end


54
55
56
# File 'lib/rails_clafer/clafer_printer.rb', line 54

def print_ref_clafer(ref_clafer)
  "#{ref_clafer.ref_name} -> #{ref_clafer.clafer_name} #{print_card(ref_clafer.card)}"
end


50
51
52
# File 'lib/rails_clafer/clafer_printer.rb', line 50

def print_reg_clafer(clafer)
  "#{print_gcard(clafer.gcard)}#{print_abstract(clafer)}#{clafer.name} #{print_card(clafer.card)}"
end