Class: Checker::Data
- Inherits:
-
Object
- Object
- Checker::Data
- Defined in:
- lib/asker/checker.rb
Overview
Internal class that revise syntax rubocop:disable Metrics/ClassLength
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
rubocop:disable Metrics/MethodLength rubocop:disable Metrics/AbcSize.
-
#initialize(filepath) ⇒ Data
constructor
rubocop:disable Metrics/MethodLength.
-
#ok? ⇒ Boolean
rubocop:enable Metrics/MethodLength.
- #show ⇒ Object
-
#show_errors ⇒ Object
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength.
Constructor Details
#initialize(filepath) ⇒ Data
rubocop:disable Metrics/MethodLength
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/asker/checker.rb', line 44 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.
40 41 42 |
# File 'lib/asker/checker.rb', line 40 def inputs @inputs end |
#outputs ⇒ Object (readonly)
Returns the value of attribute outputs.
41 42 43 |
# File 'lib/asker/checker.rb', line 41 def outputs @outputs end |
Instance Method Details
#check ⇒ Object
rubocop:disable Metrics/MethodLength rubocop:disable Metrics/AbcSize
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/asker/checker.rb', line 97 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_unknown(line, index) @ok = false unless @outputs[index][:state] == :ok @ok = false if @outputs[index][:type] == :unkown end @ok end |
#ok? ⇒ Boolean
rubocop:enable Metrics/MethodLength
60 61 62 |
# File 'lib/asker/checker.rb', line 60 def ok? @ok end |
#show ⇒ Object
64 65 66 67 68 |
# File 'lib/asker/checker.rb', line 64 def show @outputs.each do |i| puts "#{i[:id]}: #{i[:state]} [#{i[:type]}] #{i[:msg]}" end end |
#show_errors ⇒ Object
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/asker/checker.rb', line 72 def show_errors errors = 0 # puts "Line : Error description" @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] } puts format(' %<id>03d : %<msg>s. => %<source>s', data) end puts '...' if errors == 11 end if errors.positive? puts Rainbow("[ERROR] #{errors} errors " \ "from #{@inputs.size} lines!").red.bright end puts Rainbow('Syntax OK!').green if errors.zero? end |