Class: GitFormatter
- Inherits:
-
Object
- Object
- GitFormatter
- Defined in:
- lib/git_formatter.rb
Instance Method Summary collapse
- #commit_array ⇒ Object
-
#initialize(data) ⇒ GitFormatter
constructor
A new instance of GitFormatter.
-
#json_formatted ⇒ Object
TODO: Refactor.
-
#title_list(list_style) ⇒ Object
list_style = ‘ordered’ || ‘unordered’.
Constructor Details
#initialize(data) ⇒ GitFormatter
Returns a new instance of GitFormatter.
4 5 6 |
# File 'lib/git_formatter.rb', line 4 def initialize(data) @data = data end |
Instance Method Details
#commit_array ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/git_formatter.rb', line 8 def commit_array data = @data commit_array = [] unless data.empty? commit_array = data.split(/git__title:/) commit_array.reject!(&:empty?) else [] end end |
#json_formatted ⇒ Object
TODO: Refactor
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/git_formatter.rb', line 20 def json_formatted commits = commit_array hash_array = [] commits.each do |c| commit_hash = {} title = c[/.+?(?=git__description)/m] hours_logged = title[/(?<=\[)((\d*[.])?\d+)(?=\])/].to_f end_time = DateTime.parse(c[/(?<=git__date:)(.*)/]) start_time = end_time - hours_logged/24.0 commit_hash[:title] = title.gsub(/\[((\d*[.])?\d+)\]/, '') commit_hash[:description] = c[/(?<=git__description:)(.*)(?=git__date:)/m] commit_hash[:end_time] = end_time.to_s commit_hash[:start_time] = start_time.to_s hash_array.push(commit_hash) end hash_array end |
#title_list(list_style) ⇒ Object
list_style = ‘ordered’ || ‘unordered’
40 41 42 43 44 45 46 47 48 |
# File 'lib/git_formatter.rb', line 40 def title_list(list_style) hash_array = json_formatted commit_titles = hash_array.map{ |commit| commit[:title] } if list_style == 'unordered' commit_titles.join("\n") else commit_titles.each_with_index.map { |title,number| "#{number + 1}. #{title}" }.join("\n") end end |