gyunyu 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Rakefile CHANGED
@@ -31,9 +31,11 @@ RSpec::Core::RakeTask.new(:spec) do |spec|
31
31
  spec.pattern = FileList['spec/**/*_spec.rb']
32
32
  end
33
33
 
34
- RSpec::Core::RakeTask.new(:simplecov) do |spec|
35
- spec.pattern = 'spec/**/*_spec.rb'
36
- spec.rcov = true
34
+ namespace :spec do
35
+ desc 'Run Rspec & Create Coverage'
36
+ RSpec::Core::RakeTask.new(:coverage) do
37
+ ENV['COVERAGE'] = "true"
38
+ end
37
39
  end
38
40
 
39
41
  task :default => :spec
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.1
1
+ 0.3.2
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "gyunyu"
8
- s.version = "0.3.1"
8
+ s.version = "0.3.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["wtnabe"]
@@ -36,6 +36,7 @@ Gem::Specification.new do |s|
36
36
  "lib/gyunyu/command/export/format/json.rb",
37
37
  "lib/gyunyu/command/export/format/yaml.rb",
38
38
  "lib/gyunyu/command/export/option.rb",
39
+ "lib/gyunyu/command/export/total_estimate.rb",
39
40
  "lib/gyunyu/expander.rb",
40
41
  "lib/gyunyu/token.rb",
41
42
  "spec/app/.gitkeep",
@@ -43,6 +44,7 @@ Gem::Specification.new do |s|
43
44
  "spec/app/command/export/custom_filter_spec.rb",
44
45
  "spec/app/command/export/format/csv_spec.rb",
45
46
  "spec/app/command/export/option_spec.rb",
47
+ "spec/app/command/export/total_estimate_spec.rb",
46
48
  "spec/app/command_spec.rb",
47
49
  "spec/app/expander_spec.rb",
48
50
  "spec/spec_helper.rb",
@@ -5,6 +5,9 @@ module Gyunyu
5
5
  module Export
6
6
  class App
7
7
  TIME_FIELDS = %w( created modified due added completed deleted )
8
+ ESTIMATE_DAY = 'estimate(d)'
9
+ ESTIMATE_HOUR = 'estimate(h)'
10
+ ESTIMATE_MIN = 'estimate(m)'
8
11
 
9
12
  def initialize
10
13
  @argv ||= ARGV
@@ -21,7 +24,7 @@ module Gyunyu
21
24
  def fields
22
25
  ['list'] + option.fields.map { |f|
23
26
  if f == 'estimate'
24
- %w( estimate(d) estimate(h) estimate(m) )
27
+ [ESTIMATE_DAY, ESTIMATE_HOUR, ESTIMATE_MIN]
25
28
  else
26
29
  f
27
30
  end
@@ -121,9 +124,9 @@ module Gyunyu
121
124
  end
122
125
  if f == 'estimate'
123
126
  e = split_estimate( t[f] )
124
- record['estimate(d)'] = e.day
125
- record['estimate(h)'] = e.hour
126
- record['estimate(m)'] = e.min
127
+ record[ESTIMATE_DAY] = e.day
128
+ record[ESTIMATE_HOUR] = e.hour
129
+ record[ESTIMATE_MIN] = e.min
127
130
  else
128
131
  record[f] = val
129
132
  end
@@ -1,4 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
+ require File.dirname(__FILE__) + '/../total_estimate'
3
+
2
4
  if RUBY_VERSION < '1.9'
3
5
  require 'fastercsv'
4
6
  else
@@ -16,7 +18,11 @@ module Gyunyu
16
18
  @num_notes = nil
17
19
 
18
20
  class << self
21
+ include Export::TotalEstimate
22
+
19
23
  def export( tasks, fields )
24
+ sum_estimate( tasks, fields )
25
+
20
26
  FasterCSV.generate { |csv|
21
27
  tasks, fields = parse( tasks, fields )
22
28
  csv << fields
@@ -35,6 +41,12 @@ module Gyunyu
35
41
  t[f]
36
42
  }.flatten
37
43
  }
44
+
45
+ if @total_estimate
46
+ csv << fields.map { |f|
47
+ @total_estimate.has_key?(f) ? @total_estimate[f] : ''
48
+ }
49
+ end
38
50
  }
39
51
  end
40
52
 
@@ -0,0 +1,41 @@
1
+ module Gyunyu
2
+ module Command
3
+ module Export
4
+ module TotalEstimate
5
+ def sum_estimate( tasks, fields )
6
+ if have_estimate_fields?( fields )
7
+ sum = {}; estimate_fields.map { |f| sum[f] = 0 }
8
+
9
+ tasks.each { |t|
10
+ fields.grep(/\Aestimate/).each { |f|
11
+ sum[f] += t[f].to_i
12
+ }
13
+ }
14
+ @total_estimate = moveup_minute( sum )
15
+ end
16
+ end
17
+
18
+ #
19
+ # [param] Hash sum
20
+ # [return] Hash
21
+ #
22
+ def moveup_minute( sum )
23
+ movedup_hour = sum[App::ESTIMATE_MIN] / 60
24
+ sum[App::ESTIMATE_HOUR] += movedup_hour
25
+ sum[App::ESTIMATE_MIN] = sum[App::ESTIMATE_MIN] - movedup_hour * 60
26
+ sum
27
+ end
28
+
29
+ def have_estimate_fields?( fields )
30
+ estimate_fields & fields == estimate_fields
31
+ end
32
+
33
+ def estimate_fields
34
+ App.constants.map(&:to_s).grep(/\AESTIMATE/).map { |e|
35
+ App.const_get(e)
36
+ }
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,59 @@
1
+ # -*- coding: utf-8 -*-
2
+ require File.dirname(__FILE__) + '/../../../spec_helper'
3
+
4
+ describe Gyunyu::Command::Export::TotalEstimate do
5
+ include Gyunyu::Command::Export::TotalEstimate
6
+
7
+ let(:tasks) {
8
+ [
9
+ { "list" => "個人",
10
+ "name" => "gyunyu開発",
11
+ "estimate(d)" => 0,
12
+ "estimate(h)" => 2,
13
+ "estimate(m)" => 45},
14
+ { "list" => "家",
15
+ "name" => "小さな整理",
16
+ "estimate(d)" => 0,
17
+ "estimate(h)" => 0,
18
+ "estimate(m)" => 25},
19
+ { "list" => "個人",
20
+ "name" => "ありがちanalyticsコード改善",
21
+ "estimate(d)" => 0,
22
+ "estimate(h)" => 0,
23
+ "estimate(m)" => 60}
24
+ ]
25
+ }
26
+
27
+ describe 'sum_estimate' do
28
+ subject {
29
+ sum_estimate( tasks, %w{list name estimate(d) estimate(h) estimate(m)} )
30
+ }
31
+ it {
32
+ should == {
33
+ 'estimate(d)' => 0,
34
+ 'estimate(h)' => 4,
35
+ 'estimate(m)' => 10
36
+ }
37
+ }
38
+ end
39
+
40
+ describe 'have_estimate_fields?' do
41
+ context 'name, due' do
42
+ subject {
43
+ have_estimate_fields?( %w( name due ) )
44
+ }
45
+ it {
46
+ should be_false
47
+ }
48
+ end
49
+ context 'name, estimate' do
50
+ subject {
51
+ have_estimate_fields?(%w{ name estimate(d) estimate(h) estimate(m) })
52
+ }
53
+ it {
54
+ should be_true
55
+ }
56
+ end
57
+ end
58
+ end
59
+
@@ -1,12 +1,20 @@
1
1
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
2
  $LOAD_PATH.unshift(File.dirname(__FILE__))
3
3
  require 'rspec'
4
+
5
+ RSpec.configure do |config|
6
+ config.mock_with :rr
7
+ end
8
+
9
+ if ENV['COVERAGE']
10
+ require 'simplecov'
11
+ SimpleCov.start do
12
+ add_filter 'spec'
13
+ end
14
+ end
15
+
4
16
  require 'gyunyu'
5
17
 
6
18
  # Requires supporting files with custom matchers and macros, etc,
7
19
  # in ./support/ and its subdirectories.
8
20
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
-
10
- RSpec.configure do |config|
11
- config.mock_with :rr
12
- end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gyunyu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -182,6 +182,7 @@ files:
182
182
  - lib/gyunyu/command/export/format/json.rb
183
183
  - lib/gyunyu/command/export/format/yaml.rb
184
184
  - lib/gyunyu/command/export/option.rb
185
+ - lib/gyunyu/command/export/total_estimate.rb
185
186
  - lib/gyunyu/expander.rb
186
187
  - lib/gyunyu/token.rb
187
188
  - spec/app/.gitkeep
@@ -189,6 +190,7 @@ files:
189
190
  - spec/app/command/export/custom_filter_spec.rb
190
191
  - spec/app/command/export/format/csv_spec.rb
191
192
  - spec/app/command/export/option_spec.rb
193
+ - spec/app/command/export/total_estimate_spec.rb
192
194
  - spec/app/command_spec.rb
193
195
  - spec/app/expander_spec.rb
194
196
  - spec/spec_helper.rb
@@ -213,7 +215,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
213
215
  version: '0'
214
216
  segments:
215
217
  - 0
216
- hash: 3332948423612070695
218
+ hash: 328607615784605612
217
219
  required_rubygems_version: !ruby/object:Gem::Requirement
218
220
  none: false
219
221
  requirements: