diff --git a/bin/git-timecost b/bin/git-timecost index 1258eff..5319863 100755 --- a/bin/git-timecost +++ b/bin/git-timecost @@ -6,7 +6,6 @@ require 'date' require 'optparse' require 'yaml' -$:.insert 0, 'lib' require 'timecost' app = TimeCost::CLI.new diff --git a/lib/timecost/cli.rb b/lib/timecost/cli.rb index fad7298..6a8b28b 100644 --- a/lib/timecost/cli.rb +++ b/lib/timecost/cli.rb @@ -95,7 +95,7 @@ module TimeCost id = $1 # merge ranges & push unless commit.nil? then - range = Range.new @config, commit + range = Range.new commit, granularity: @config[:range_granularity] if not @rangelist.include? commit.author then @rangelist[commit.author] = RangeList.new @@ -177,7 +177,7 @@ module TimeCost @rangelist.each do |author,rangelist| rangelist.each do |range| - puts range.to_s + "\n" + puts range.to_s(!@config[:author_filter_enable]) + "\n" end end total = 0 diff --git a/lib/timecost/range.rb b/lib/timecost/range.rb index 627d69f..ed0f11e 100644 --- a/lib/timecost/range.rb +++ b/lib/timecost/range.rb @@ -3,15 +3,17 @@ module TimeCost class Range attr_accessor :time_start, :time_stop, :commits, :author - def initialize config, commit - @config = config + GRANULARITY_DEFAULT = 0.5 + + def initialize commit, options = {} + @granularity = options[:granularity] || GRANULARITY_DEFAULT # FIXME: First approximation for users # later, we'll replace with @user = User.parse(commit.author) @author = commit.author @time_stop = DateTime.parse(commit.date) - @time_start = @time_stop - (@config[:range_granularity] * 3 / 24.0) + @time_start = @time_stop - (@granularity * 3 / 24.0) @commits = [commit] self end @@ -89,16 +91,16 @@ module TimeCost end def fixed_start - return @time_start + (@config[:range_granularity]/24.0) + return @time_start + (@granularity/24.0) end def diff return ("%.2f" % ((@time_stop - fixed_start).to_f * 24)).to_f end - def to_s + def to_s show_authors = true val = "(%s)\t%s - %s\n" % [diff, fixed_start, @time_stop] - unless @config[:author_filter_enable] then + if show_authors then val += "\tby %s\n" % @commits.first.author end @commits.each do |commit| diff --git a/spec/cli_spec.rb b/spec/cli_spec.rb new file mode 100644 index 0000000..6e15f64 --- /dev/null +++ b/spec/cli_spec.rb @@ -0,0 +1,16 @@ + + +require_relative 'spec_helper' + +require 'timecost/cli' + +describe TimeCost::CLI do + let(:cli) { TimeCost::CLI.new } + + describe '.new' do + it "can be created without arguments" do + assert_instance_of TimeCost::CLI, cli + end + end + +end diff --git a/spec/range_list_spec.rb b/spec/range_list_spec.rb index e69de29..20e83b5 100644 --- a/spec/range_list_spec.rb +++ b/spec/range_list_spec.rb @@ -0,0 +1,26 @@ + +require_relative 'spec_helper' + +require 'timecost/range_list' + +describe TimeCost::RangeList do + let(:list) { TimeCost::RangeList.new } + + describe '.new' do + it "can be created without arguments" do + assert_instance_of TimeCost::RangeList, list + end + end + + it "is empty at start" do + end + + it "can insert ranges" do + end + + it "can merge overlapping ranges" do + end + + it "cumulates non-overlapping ranges" do + end +end diff --git a/spec/range_spec.rb b/spec/range_spec.rb index e69de29..17fba79 100644 --- a/spec/range_spec.rb +++ b/spec/range_spec.rb @@ -0,0 +1,35 @@ + +require_relative 'spec_helper' + +require 'timecost/range' + +describe TimeCost::Range do + let(:config) do { granularity: 0.5 } end + + let(:commitA) { nil } + let(:commitB) { nil } + let(:commitC) { nil } + let(:commitD) { nil } + + let(:rangeA) { + TimeCost::Range.new commitA, config + } + + describe '.new' do + it "can be created from " do + assert_instance_of TimeCost::Range, rangeA + end + end + + describe '.overlap?' do + it "must respond to .overlap?" do + end + + it "must return false when ranges are not overlapping" do + end + + it "must return true when ranges are overlapping" do + end + end +end +