Module: CheckTable

Included in:
CheckHamlData
Defined in:
lib/asker/check_input/check_table.rb

Instance Method Summary collapse

Instance Method Details

#check_col(line, index) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/asker/check_input/check_table.rb', line 55

def check_col(line, index)
  return unless @outputs[index][:state] == :none
  return unless line.include? "%col"

  @outputs[index][:type] = :col
  @outputs[index][:state] = :ok

  # row parent requires empty msg
  if @outputs[index - 1][:type] == :row
    if @outputs[index - 1][:source].strip != "%row"
      @outputs[index - 1][:state] = :err
      @outputs[index - 1][:msg] = "Row with cols requires empty text!"
    end
  end

  case count_spaces(line)
  when 8
    @outputs[index][:level] = 4
    if find_parent(index) != :row
      @outputs[index][:state] = :err
      @outputs[index][:msg] = "Parent(row) not found!"
    end
  when 10
    @outputs[index][:level] = 5
    if find_parent(index) != :row
      @outputs[index][:state] = :err
      @outputs[index][:msg] = "Parent(row) not found!"
    end
  else
    @outputs[index][:state] = :err
    @outputs[index][:msg] = "Write 8 or 10 spaces before %col"
  end
  check_text(line, index)
end

#check_row(line, index) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/asker/check_input/check_table.rb', line 28

def check_row(line, index)
  return unless @outputs[index][:state] == :none
  return unless line.include? "%row"

  @outputs[index][:type] = :row
  @outputs[index][:state] = :ok

  case count_spaces(line)
  when 6
    @outputs[index][:level] = 3
    parent = find_parent(index)
    unless %i[table template features].include? parent
      @outputs[index][:state] = :err
      @outputs[index][:msg] = "Parent(table/template/features) not found!"
    end
  when 8
    @outputs[index][:level] = 4
    if find_parent(index) != :template
      @outputs[index][:state] = :err
      @outputs[index][:msg] = "Parent(template) not found!"
    end
  else
    @outputs[index][:state] = :err
    @outputs[index][:msg] = "Write 6 or 8 spaces before %row"
  end
end

#check_table(line, index) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/asker/check_input/check_table.rb', line 2

def check_table(line, index)
  return unless @outputs[index][:state] == :none
  return unless line.include? "%table"

  @outputs[index][:type] = :table
  @outputs[index][:level] = 2
  @outputs[index][:state] = :ok
  if find_parent(index) != :concept
    @outputs[index][:state] = :err
    @outputs[index][:msg] = "Parent(concept) not found!"
  elsif !line.match(/^\s\s\s\s%table\s*/)
    @outputs[index][:state] = :err
    @outputs[index][:msg] = "Write 4 spaces before %table"
  end

  unless line.include? "%table{"
    @outputs[index][:state] = :err
    @outputs[index][:msg] = "table must be next to { (Without spaces)"
  end

  unless line.include? "fields:"
    @outputs[index][:state] = :err
    @outputs[index][:msg] = "fields must be next to : (Without spaces)"
  end
end

#check_template(line, index) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/asker/check_input/check_table.rb', line 103

def check_template(line, index)
  return unless @outputs[index][:state] == :none
  return unless line.include? "%template"

  @outputs[index][:type] = :template
  @outputs[index][:level] = 3
  @outputs[index][:state] = :ok
  if find_parent(index) != :table
    @outputs[index][:state] = :err
    @outputs[index][:msg] = "Parent(concept) not found!"
  elsif !line.match(/^\s\s\s\s\s\s%template\s*/)
    @outputs[index][:state] = :err
    @outputs[index][:msg] = "Write 6 spaces before %template"
  end
end

#check_text(line, index) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/asker/check_input/check_table.rb', line 90

def check_text(line, index)
  return unless @outputs[index][:state] == :ok

  ok = ""
  %w[< >].each do |char|
    ok = char if line.include? char
  end
  return if ok == ""

  @outputs[index][:state] = :err
  @outputs[index][:msg] = "Char #{ok} not allow!"
end