Sha256: ba49af711f09518cff1d8382b8e5076ca31c60f1072038ef9d4de75cce0beabc

Contents?: true

Size: 1.25 KB

Versions: 23

Compression:

Stored size: 1.25 KB

Contents

require 'yaml'

class YamlLint


  def self.parse_file(file, learn_error)
    begin
      YAML.load_file(file)
    rescue Exception => err
      learn_error.valid_yaml = {message: "#{err}", color: :red}
    else
      learn_error.yaml_error[:valid_yaml] = true
      if check_attributes(file)
        learn_error.yaml_error[:attributes] = true
        learn_error.correct_yaml_content = {message: "valid attribute key names", color: :green}
      end
      if self.validate_whitespace_for_learn(file)
        learn_error.yaml_error[:valid_whitespace] = true
        learn_error.valid_yaml = {message: "valid yaml and valid whitespace.", color: :green}
      else 
        learn_error.valid_yaml = {message: "valid yaml but invalid whitespace", color: :red}
      end
    end
  end

  def self.validate_whitespace_for_learn(file)
    lines = file_lines(file).split("\n")
    attributes = lines.select { |line| line.include?("-") }
    attributes.each do |attribute| 
      return false unless attribute[0..3] == "  - "
    end
    true
  end 

   def self.check_attributes(file)
    file_string = file_lines(file)
    file_string.match(/tags/) && file_string.match(/resources/) && file_string.match(/languages/)
  end

  def self.file_lines(file)
    f = File.read(file)
  end

end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
learn_linter-1.7.3 lib/learn_linter/yaml_linter.rb
learn_linter-1.7.2 lib/learn_linter/yaml_linter.rb
learn_linter-1.7.1 lib/learn_linter/yaml_linter.rb
learn_linter-1.7.0 lib/learn_linter/yaml_linter.rb
learn_linter-1.6.9 lib/learn_linter/yaml_linter.rb
learn_linter-1.6.8 lib/learn_linter/yaml_linter.rb
learn_linter-1.6.7 lib/learn_linter/yaml_linter.rb
learn_linter-1.6.5 lib/learn_linter/yaml_linter.rb
learn_linter-1.6.4 lib/learn_linter/yaml_linter.rb
learn_linter-1.6.3 lib/learn_linter/yaml_linter.rb
learn_linter-1.6.2 lib/learn_linter/yaml_linter.rb
learn_linter-1.6.1 lib/learn_linter/yaml_linter.rb
learn_linter-1.6.0 lib/learn_linter/yaml_linter.rb
learn_linter-1.5.0 lib/learn_linter/yaml_linter.rb
learn_linter-1.4.0 lib/learn_linter/yaml_linter.rb
learn_linter-1.3.0 lib/learn_linter/yaml_linter.rb
learn_linter-1.2.0 lib/learn_linter/yaml_linter.rb
learn_linter-1.1.0 lib/learn_linter/yaml_linter.rb
learn_linter-0.6.0 lib/learn_linter/yaml_linter.rb
learn_linter-0.5.0 lib/learn_linter/yaml_linter.rb