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
- #run_and_raise ⇒ Object
-
#with_ignored(ignored_a) ⇒ Object
which html elements to ignore.
Constructor Details
#initialize ⇒ Base
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
#dirs ⇒ Object
Returns the value of attribute dirs.
63 64 65 |
# File 'lib/komplement/base.rb', line 63 def dirs @dirs end |
#files_of_interest ⇒ Object (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 |
#filetypes ⇒ Object
Returns the value of attribute filetypes.
62 63 64 |
# File 'lib/komplement/base.rb', line 62 def filetypes @filetypes end |
#ignored_elements ⇒ Object
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_offenses ⇒ Object
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 |
#run ⇒ Object
29 30 31 |
# File 'lib/komplement/base.rb', line 29 def run process_output(find_offenses) end |
#run_and_raise ⇒ Object
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 |