Class: Komplement::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/komplement/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBase

Returns a new instance of Base.



7
8
9
# File 'lib/komplement/base.rb', line 7

def initialize
  @ignored_elements = @filetypes = @dirs = []
end

Instance Attribute Details

#dirsObject

Returns the value of attribute dirs.



63
64
65
# File 'lib/komplement/base.rb', line 63

def dirs
  @dirs
end

#files_of_interestObject (readonly)

Returns the value of attribute files_of_interest.



65
66
67
# File 'lib/komplement/base.rb', line 65

def files_of_interest
  @files_of_interest
end

#filetypesObject

Returns the value of attribute filetypes.



62
63
64
# File 'lib/komplement/base.rb', line 62

def filetypes
  @filetypes
end

#ignored_elementsObject

Returns the value of attribute ignored_elements.



61
62
63
# File 'lib/komplement/base.rb', line 61

def ignored_elements
  @ignored_elements
end

Instance Method Details

#find_offensesObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/komplement/base.rb', line 42

def find_offenses
  [@ignored_elements, @filetypes, @dirs].map { |e| e.uniq! }

  paths = make_paths
  @files_of_interest = make_files(paths)

  unknown = Hash.new { |h, k| h[k] = [] }

  @files_of_interest.each do |file|
    contents = File.read(file)
    Nokogiri::HTML(contents).traverse do |node|
      unless @ignored_elements.include? nm = node.name
        unknown[file].push nm
      end
    end
  end
  unknown
end

#in_dirs(dirs_a) ⇒ Object

all the paths we should look into



24
25
26
27
# File 'lib/komplement/base.rb', line 24

def in_dirs(dirs_a)
  @dirs += dirs_a
  self
end

#in_filetypes(filetypes_a) ⇒ Object

filetypes to look into for html elements



18
19
20
21
# File 'lib/komplement/base.rb', line 18

def in_filetypes(filetypes_a)
  @filetypes = filetypes_a.map { |e| "*.#{e}" }
  self
end

#runObject



29
30
31
# File 'lib/komplement/base.rb', line 29

def run
  process_output(find_offenses)
end

#run_and_raiseObject



33
34
35
36
37
38
39
40
# File 'lib/komplement/base.rb', line 33

def run_and_raise
  ret = run
  if ret != 0
    raise Komplement::Error, "there were problems with your html"
  else
    ret
  end
end

#with_ignored(ignored_a) ⇒ Object

which html elements to ignore



12
13
14
15
# File 'lib/komplement/base.rb', line 12

def with_ignored(ignored_a)
  @ignored_elements += ignored_a
  self
end