Class: CheckHamlData
- Inherits:
-
Object
- Object
- CheckHamlData
- Includes:
- CheckTable
- Defined in:
- lib/asker/check_input/check_haml_data.rb
Instance Attribute Summary collapse
-
#inputs ⇒ Object
readonly
Returns the value of attribute inputs.
-
#outputs ⇒ Object
readonly
Returns the value of attribute outputs.
Instance Method Summary collapse
- #check ⇒ Object
-
#initialize(filepath) ⇒ CheckHamlData
constructor
A new instance of CheckHamlData.
- #ok? ⇒ Boolean
- #show ⇒ Object
- #show_errors ⇒ Object
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
#inputs ⇒ Object (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 |
#outputs ⇒ Object (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
#check ⇒ Object
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) (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
22 23 24 |
# File 'lib/asker/check_input/check_haml_data.rb', line 22 def ok? @ok end |
#show ⇒ Object
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_errors ⇒ Object
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]} = Rainbow(" %<order>03d : %<msg>32s. => ").white = Rainbow("%<source>s").yellow.bright output = format(, data) + format(, data) warn output end warn "..." if errors == 11 end if errors.zero? puts Rainbow("Syntax OK!").green.bright else = "\nRevise #{errors} syntax warning or error/s\n" warn Rainbow().yellow.bright exit 1 end end |