Class: TodosExport::Main
- Inherits:
-
Object
- Object
- TodosExport::Main
- Defined in:
- lib/todos_export.rb
Instance Attribute Summary collapse
-
#exportables ⇒ Object
Returns the value of attribute exportables.
-
#files ⇒ Object
Returns the value of attribute files.
-
#target ⇒ Object
Returns the value of attribute target.
Instance Method Summary collapse
- #delete_exportable(file, line) ⇒ Object
- #delete_exportables ⇒ Object
- #execute ⇒ Object
- #exportable_bugs ⇒ Object
- #exportable_fixmes ⇒ Object
- #exportable_todos ⇒ Object
- #find_exportables ⇒ Object
- #find_files ⇒ Object
-
#initialize(target) ⇒ Main
constructor
A new instance of Main.
Constructor Details
#initialize(target) ⇒ Main
Returns a new instance of Main.
11 12 13 14 |
# File 'lib/todos_export.rb', line 11 def initialize(target) self.target = target self.exportables = [] end |
Instance Attribute Details
#exportables ⇒ Object
Returns the value of attribute exportables.
9 10 11 |
# File 'lib/todos_export.rb', line 9 def exportables @exportables end |
#files ⇒ Object
Returns the value of attribute files.
9 10 11 |
# File 'lib/todos_export.rb', line 9 def files @files end |
#target ⇒ Object
Returns the value of attribute target.
9 10 11 |
# File 'lib/todos_export.rb', line 9 def target @target end |
Instance Method Details
#delete_exportable(file, line) ⇒ Object
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/todos_export.rb', line 63 def delete_exportable(file, line) lines = File.readlines(file) lines.delete_at(line - 1) File.open(file, "w") do |f| lines.each { |l| f.puts(l) } end self.find_exportables end |
#delete_exportables ⇒ Object
74 75 76 77 78 79 |
# File 'lib/todos_export.rb', line 74 def delete_exportables while !self.exportables.empty? do self.delete_exportable(self.exportables[0][:file], self.exportables[0][:line]) self.find_exportables end end |
#execute ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/todos_export.rb', line 81 def execute self.find_exportables say("Found #{self.exportable_todos.size} TODO's, " \ "#{self.exportable_fixmes.size} FIXME's and " \ "#{self.exportable_bugs.size} BUG's" \ " in #{self.exportables.map { |x| x[:file] }.uniq.size } of #{exportables.map { |x| x[:file] }.size } files searched.") say("\n") choose do || .prompt = "Export to: " .choice('Github Issues') { TodosExport::GithubIssues.new(self).run } end end |
#exportable_bugs ⇒ Object
59 60 61 |
# File 'lib/todos_export.rb', line 59 def exportable_bugs self.exportables.select { |x| x[:type] == 'BUG' } end |
#exportable_fixmes ⇒ Object
55 56 57 |
# File 'lib/todos_export.rb', line 55 def exportable_fixmes self.exportables.select { |x| x[:type] == 'FIXME' } end |
#exportable_todos ⇒ Object
51 52 53 |
# File 'lib/todos_export.rb', line 51 def exportable_todos self.exportables.select { |x| x[:type] == 'TODO' } end |
#find_exportables ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/todos_export.rb', line 28 def find_exportables self.find_files @exportables = [] self.files.each do |file| File.open(file) do |f| f.each_with_index do |line, number| search = line.scan(/((?:#)(?:| )(TODO|FIXME|BUG):?(.*)$)/i) if !search.empty? self.exportables << { :type => search[0][1].upcase, :content => search[0][2].strip, :original_content => search[0][0], :file => file.gsub(/^(.\/)/, ''), :original_file => file, :line => number + 1 } end end end end end |
#find_files ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/todos_export.rb', line 16 def find_files if File.file?(self.target) self.files = [self.target] elsif File.directory?(self.target) self.files = Dir.glob(File.join(self.target, "**", "*.rb")) else abort "#{target} does not exist." end return self.files end |