Class: CheckHamlData

Inherits:
Object
  • Object
show all
Includes:
CheckTable
Defined in:
lib/asker/check_input/check_haml_data.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CheckTable

#check_col, #check_row, #check_table, #check_template

Constructor Details

#initialize(filepath) ⇒ CheckHamlData

Returns a new instance of CheckHamlData.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/asker/check_input/check_haml_data.rb', line 7

def initialize(filepath)
  @inputs = File.read(filepath).split("\n")
  @outputs = []
  @inputs.each_with_index do |line, index|
    output = {id: index,
              level: 0,
              state: :none,
              type: :none,
              source: line,
              msg: ""}
    @outputs << output
  end
  @ok = false
end

Instance Attribute Details

#inputsObject (readonly)

Returns the value of attribute inputs.



5
6
7
# File 'lib/asker/check_input/check_haml_data.rb', line 5

def inputs
  @inputs
end

#outputsObject (readonly)

Returns the value of attribute outputs.



5
6
7
# File 'lib/asker/check_input/check_haml_data.rb', line 5

def outputs
  @outputs
end

Instance Method Details

#checkObject



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
89
# File 'lib/asker/check_input/check_haml_data.rb', line 59

def check
  @ok = true
  @inputs.each_with_index do |line, index|
    check_empty_lines(line, index)
    check_map(line, index)
    check_concept(line, index)
    check_names(line, index)
    check_tags(line, index)
    check_def(line, index)
    check_table(line, index)
    check_row(line, index)
    check_col(line, index)
    check_template(line, index)
    check_code(line, index)
    check_type(line, index)
    check_path(line, index)
    check_features(line, index)
    check_problem(line, index)
    check_cases(line, index)
    check_case(line, index)
    check_desc(line, index)
    check_ask(line, index)
    check_text(line, index)
    check_answer(line, index)
    check_step(line, index)
    check_unknown(line, index)
    @ok = false unless @outputs[index][:state] == :ok
    @ok = false if @outputs[index][:type] == :unkown
  end
  @ok
end

#ok?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/asker/check_input/check_haml_data.rb', line 22

def ok?
  @ok
end

#showObject



26
27
28
29
30
# File 'lib/asker/check_input/check_haml_data.rb', line 26

def show
  @outputs.each do |i|
    puts "#{i[:id]}: #{i[:state]} [#{i[:type]}] #{i[:msg]}"
  end
end

#show_errorsObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/asker/check_input/check_haml_data.rb', line 32

def show_errors
  errors = 0
  @outputs.each do |i|
    next if i[:state] == :ok

    errors += 1
    if errors < 11
      data = {id: i[:id], msg: i[:msg], source: i[:source][0, 40]}
      order = i[:id] + 1
      data = {order: order, msg: i[:msg], source: i[:source][0, 40]}
      message1 = Rainbow(" %<order>03d : %<msg>32s. => ").white
      message2 = Rainbow("%<source>s").yellow.bright
      output = format(message1, data) + format(message2, data)
      warn output
    end
    warn "..." if errors == 11
  end

  if errors.zero?
    puts Rainbow("Syntax OK!").green.bright
  else
    message = "\nRevise #{errors} syntax warning or error/s\n"
    warn Rainbow(message).yellow.bright
    exit 1
  end
end