calc_working_hours 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,7 +6,11 @@ module CalcWorkingHours
6
6
 
7
7
  class TimeCardRow
8
8
  attr_reader :starting_time, :ending_time, :break_time, :working_hours, :date_string, :time_point, :working_hours_in_range, :overtime, :id
9
- def initialize(starting_time, ending_time, *break_time)
9
+ def initialize(date_string, starting_time, ending_time, *break_time)
10
+ unless date_string.class == String
11
+ raise "failure set_date (date should string class)! TimeCardRow class"
12
+ end
13
+
10
14
  unless CalcHelper.valid_time_format?(starting_time) && CalcHelper.valid_time_format?(ending_time)
11
15
  raise "failure initialize (invalid time format! TimeCardRow class)"
12
16
  end
@@ -31,7 +35,7 @@ module CalcWorkingHours
31
35
  unless break_time.empty?
32
36
  total_break_time_string = CalcHelper.total_break_time(break_time).time_string
33
37
  end
34
-
38
+ @date_string = date_string
35
39
  @starting_time = starting_time
36
40
  @ending_time = ending_time
37
41
  @break_time = break_time
@@ -59,14 +63,6 @@ module CalcWorkingHours
59
63
  self
60
64
  end
61
65
 
62
- def set_date(date)
63
- unless date.class == String
64
- raise "failure set_date (date should string class)! TimeCardRow class"
65
- end
66
- @date_string = date
67
- self
68
- end
69
-
70
66
  def working_hours_in_range(start_range, end_range)
71
67
  i = @time_point.size / 2
72
68
  starting_time, ending_time = ""
@@ -5,7 +5,7 @@ module CalcWorkingHours
5
5
 
6
6
  class TimeRecorder
7
7
  attr_reader :time_cards
8
- def initialize(path_to_csv, set_encode, id_row, card_id_row, starting_time_row, ending_time_row, date_row, *break_time_rows)
8
+ def initialize(path_to_csv, set_encode, id_row, card_id_row, date_row, starting_time_row, ending_time_row, *break_time_rows)
9
9
 
10
10
  csv_data = File.read(path_to_csv) if set_encode == nil || set_encode == false
11
11
  csv_data = File.read(path_to_csv, :encoding => set_encode + ":UTF-8") if set_encode
@@ -27,10 +27,10 @@ module CalcWorkingHours
27
27
 
28
28
  if time_cards.has_key?(row[card_id_row])
29
29
  raise "id mismatching! (TimeRecorder class)" unless time_cards[row[card_id_row]].id == row[id_row]
30
- time_cards[row[card_id_row]].add_row(TimeCardRow.new(row[starting_time_row], row[ending_time_row], *break_times).set_date(row[date_row]))
30
+ time_cards[row[card_id_row]].add_row(TimeCardRow.new(row[date_row], row[starting_time_row], row[ending_time_row], *break_times))
31
31
  else
32
32
  time_cards[row[card_id_row]] = TimeCard.new(row[card_id_row], row[id_row])
33
- time_cards[row[card_id_row]].add_row(TimeCardRow.new(row[starting_time_row], row[ending_time_row], *break_times).set_date(row[date_row]))
33
+ time_cards[row[card_id_row]].add_row(TimeCardRow.new(row[date_row], row[starting_time_row], row[ending_time_row], *break_times))
34
34
  end
35
35
  end
36
36
  end
@@ -1,3 +1,3 @@
1
1
  module CalcWorkingHours
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
@@ -6,7 +6,7 @@ include CalcWorkingHours
6
6
  describe TimeCardRow do
7
7
  context "始業9:00、終業19:00、休憩11:00〜12:00、15:00〜16:00のとき" do
8
8
  before do
9
- @time_card_row = TimeCardRow.new("9:00", "19:00", ["11:00", "12:00"], ["15:00", "16:00"])
9
+ @time_card_row = TimeCardRow.new("2013/5/12", "9:00", "19:00", ["11:00", "12:00"], ["15:00", "16:00"])
10
10
  end
11
11
 
12
12
  it "始業時間は9:00となっている" do
@@ -21,14 +21,6 @@ describe TimeCardRow do
21
21
  @time_card_row.working_hours.time_string.should == "8:00"
22
22
  end
23
23
 
24
- it "set_dateに日付(任意の文字列)を設定できる" do
25
- @time_card_row.set_date("2013/8/1").date_string.class.should == String
26
- end
27
-
28
- it "set_dateにString以外を設定すると例外が発生する" do
29
- proc { @time_card_row.set_date(Date.new(2013,8,1)) }.should raise_error
30
- end
31
-
32
24
  it "time_pointは9:00,11:00,12:00,15:00,16:00,19:00" do
33
25
  @time_card_row.time_point.should == ["9:00", "11:00", "12:00", "15:00", "16:00", "19:00"]
34
26
  end
@@ -57,7 +49,7 @@ describe TimeCardRow do
57
49
 
58
50
  context "始業11:30、終業23:34、休憩15:38〜17:14のとき" do
59
51
  before do
60
- @time_card_row = TimeCardRow.new("11:30", "23:34", ["15:38", "17:14"])
52
+ @time_card_row = TimeCardRow.new("2013/5/12", "11:30", "23:34", ["15:38", "17:14"])
61
53
  end
62
54
 
63
55
  it "所定労働時間を8:00とすると、残業時間は2:28となる" do
@@ -67,36 +59,40 @@ describe TimeCardRow do
67
59
 
68
60
 
69
61
  context "適正な時間設定と、不適な設定時間を設定したとき" do
62
+ it "set_dateにString以外を設定すると例外が発生する" do
63
+ proc { TimeCardRow.new(Date.new(2013, 5, 12), "22:00", "28:00") }.should raise_error
64
+ end
65
+
70
66
  it "始業22:00、終業28:00は適正な始業・終業時間設定(0:00〜48:00)なので、エラーは発生しないこと" do
71
- proc{ TimeCardRow.new("22:00", "28:00") }.should_not raise_error
67
+ proc{ TimeCardRow.new("2013/5/12", "22:00", "28:00") }.should_not raise_error
72
68
  end
73
69
 
74
70
  it "始業44:00、終業50:00は不適正な始業・終業時間設定なので、エラーが発生すること" do
75
- proc{ TimeCardRow.new("44:00", "50:00") }.should raise_error
71
+ proc{ TimeCardRow.new("2013/5/12", "44:00", "50:00") }.should raise_error
76
72
  end
77
73
 
78
74
  it "始業四:00、終業5:00は不適正な時間フォーマットなので、エラーが発生すること" do
79
- proc{ TimeCardRow.new("四:00", "5:00") }.should raise_error
75
+ proc{ TimeCardRow.new("2013/5/12", "四:00", "5:00") }.should raise_error
80
76
  end
81
77
 
82
78
  it "始業9:00、終業19:00の時系列に誤りが無いので、エラーは発生しないこと" do
83
- proc { TimeCardRow.new("9:00", "19:00") }.should_not raise_error
79
+ proc { TimeCardRow.new("2013/5/12", "9:00", "19:00") }.should_not raise_error
84
80
  end
85
81
 
86
82
  it "始業18:00、終業8:00は時系列が誤っているので、エラーが発生すること" do
87
- proc { TimeCardRow.new("18:00", "9:00") }.should raise_error
83
+ proc { TimeCardRow.new("2013/5/12", "18:00", "9:00") }.should raise_error
88
84
  end
89
85
 
90
86
  it "始業8:00、終業19:00、休憩12:00〜11:00は時系列が誤っているので、エラーが発生すること" do
91
- proc { TimeCardRow.new("8:00", "19:00", ["12:00", "10:00"]) }.should raise_error
87
+ proc { TimeCardRow.new("2013/5/12", "8:00", "19:00", ["12:00", "10:00"]) }.should raise_error
92
88
  end
93
89
 
94
90
  it "始業8:00、終業19:00、休憩12:00は休憩時間設定が誤っているので、エラーが発生すること" do
95
- proc { TimeCardRow.new("8:00", "19:00", "12:00") }.should raise_error
91
+ proc { TimeCardRow.new("2013/5/12", "8:00", "19:00", "12:00") }.should raise_error
96
92
  end
97
93
 
98
94
  it "始業8:00、終業19:00、休憩7:00〜11:00は時系列が誤っているので、エラーが発生すること" do
99
- proc { TimeCardRow.new("8:00", "19:00", ["7:00", "10:00"]) }.should raise_error
95
+ proc { TimeCardRow.new("2013/5/12", "8:00", "19:00", ["7:00", "10:00"]) }.should raise_error
100
96
  end
101
97
 
102
98
  end
@@ -7,7 +7,7 @@ describe TimeRecorder do
7
7
  context "data_sample.csv(Shift_JIS)の通りTimeRecorderが与えられている場合" do
8
8
  before do
9
9
  path_to_csv = File.expand_path(File.dirname(__FILE__)) + "/data_sample.csv"
10
- @time_recorder = TimeRecorder.new(path_to_csv, "Shift_JIS", "従業員番号", "カード番号", "出勤打刻", "退勤打刻", "年/月/日", ["外出打刻", "戻打刻"])
10
+ @time_recorder = TimeRecorder.new(path_to_csv, "Shift_JIS", "従業員番号", "カード番号", "年/月/日", "出勤打刻", "退勤打刻", ["外出打刻", "戻打刻"])
11
11
  end
12
12
 
13
13
  it "タイムカードのデータが5件あること" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: calc_working_hours
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2013-09-23 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
16
- requirement: &70285409908500 !ruby/object:Gem::Requirement
16
+ requirement: &70203738463680 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '1.3'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70285409908500
24
+ version_requirements: *70203738463680
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &70285409907800 !ruby/object:Gem::Requirement
27
+ requirement: &70203738462920 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70285409907800
35
+ version_requirements: *70203738462920
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &70285409907060 !ruby/object:Gem::Requirement
38
+ requirement: &70203738462180 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70285409907060
46
+ version_requirements: *70203738462180
47
47
  description: 例えば、173:08のような表記の時間を計算するライブラリです
48
48
  email:
49
49
  - ''
@@ -89,7 +89,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
89
89
  version: '0'
90
90
  segments:
91
91
  - 0
92
- hash: -1838675914513887134
92
+ hash: 2883912784685005867
93
93
  required_rubygems_version: !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
@@ -98,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
98
  version: '0'
99
99
  segments:
100
100
  - 0
101
- hash: -1838675914513887134
101
+ hash: 2883912784685005867
102
102
  requirements: []
103
103
  rubyforge_project:
104
104
  rubygems_version: 1.8.10