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



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
# File 'lib/asker/check_input/check_table.rb', line 63

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

  @outputs[index][:type] = :col
  @outputs[index][:state] = :ok
  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



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/asker/check_input/check_table.rb', line 36

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 features].include? parent
      @outputs[index][:state] = :err
      @outputs[index][:msg] = 'Parent(table/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



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/asker/check_input/check_table.rb', line 4

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.start_with? '    %table'
    @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

  # TODO
  #else not /\s+%table{\s?fields:\s?'[A-Za-z,áéíóú]*'\s?}/.match(line)
  #  @outputs[index][:state] = :err
  #  @outputs[index][:msg] = 'Table#fields malformed!'
  #end
end

#check_template(line, index) ⇒ Object



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

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.start_with? '      %template'
    @outputs[index][:state] = :err
    @outputs[index][:msg] = 'Write 6 spaces before %template'
  end
end

#check_text(line, index) ⇒ Object



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

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