Class: Komplement::Base
- Inherits:
-
Object
- Object
- Komplement::Base
- Defined in:
- lib/komplement/base.rb
Instance Attribute Summary collapse
-
#dirs ⇒ Object
Returns the value of attribute dirs.
-
#files_of_interest ⇒ Object
readonly
Returns the value of attribute files_of_interest.
-
#filetypes ⇒ Object
Returns the value of attribute filetypes.
-
#ignored_elements ⇒ Object
Returns the value of attribute ignored_elements.
Instance Method Summary collapse
- #find_offenses ⇒ Object
-
#in_dirs(dirs_a) ⇒ Object
all the paths we should look into.
-
#in_filetypes(filetypes_a) ⇒ Object
filetypes to look into for html elements.
-
#initialize ⇒ Base
constructor
A new instance of Base.
-
#run ⇒ Object
returns 0 on no offenses, else 2.
-
#with_ignored(ignored_a) ⇒ Object
which html elements to ignore.
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
5 6 7 |
# File 'lib/komplement/base.rb', line 5 def initialize @ignored_elements = @filetypes = @dirs = [] end |
Instance Attribute Details
#dirs ⇒ Object
Returns the value of attribute dirs.
54 55 56 |
# File 'lib/komplement/base.rb', line 54 def dirs @dirs end |
#files_of_interest ⇒ Object (readonly)
Returns the value of attribute files_of_interest.
56 57 58 |
# File 'lib/komplement/base.rb', line 56 def files_of_interest @files_of_interest end |
#filetypes ⇒ Object
Returns the value of attribute filetypes.
53 54 55 |
# File 'lib/komplement/base.rb', line 53 def filetypes @filetypes end |
#ignored_elements ⇒ Object
Returns the value of attribute ignored_elements.
52 53 54 |
# File 'lib/komplement/base.rb', line 52 def ignored_elements @ignored_elements end |
Instance Method Details
#find_offenses ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/komplement/base.rb', line 33 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
22 23 24 25 |
# File 'lib/komplement/base.rb', line 22 def in_dirs(dirs_a) @dirs += dirs_a self end |
#in_filetypes(filetypes_a) ⇒ Object
filetypes to look into for html elements
16 17 18 19 |
# File 'lib/komplement/base.rb', line 16 def in_filetypes(filetypes_a) @filetypes = filetypes_a.map { |e| "*.#{e}" } self end |
#run ⇒ Object
returns 0 on no offenses, else 2
28 29 30 31 |
# File 'lib/komplement/base.rb', line 28 def run unknown = find_offenses exit process_output(unknown) end |
#with_ignored(ignored_a) ⇒ Object
which html elements to ignore
10 11 12 13 |
# File 'lib/komplement/base.rb', line 10 def with_ignored(ignored_a) @ignored_elements += ignored_a self end |