Add profile class
This commit is contained in:
parent
3195a14bb3
commit
e9fa65a8f7
@ -11,3 +11,8 @@ targets:
|
|||||||
crystal: 0.31.1
|
crystal: 0.31.1
|
||||||
|
|
||||||
license: MIT
|
license: MIT
|
||||||
|
|
||||||
|
development_dependencies:
|
||||||
|
ameba:
|
||||||
|
github: crystal-ameba/ameba
|
||||||
|
version: ~> 0.10.1
|
||||||
|
@ -2,18 +2,14 @@ require "./spec_helper"
|
|||||||
|
|
||||||
describe Dayoff do
|
describe Dayoff do
|
||||||
it "can calc work hours" do
|
it "can calc work hours" do
|
||||||
app = Dayoff::App.new(
|
app = Dayoff::App.new
|
||||||
"./spec/data/planned-dates.json",
|
prof = app.profile("./spec/data")
|
||||||
"./spec/data/work-records.json",
|
prof.get_planned_hours.should eq 20
|
||||||
)
|
|
||||||
app.get_planned_hours.should eq 20
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "can calc work hours" do
|
it "can calc work hours" do
|
||||||
app = Dayoff::App.new(
|
app = Dayoff::App.new
|
||||||
"./spec/data/planned-dates.json",
|
prof = app.profile("./spec/data")
|
||||||
"./spec/data/work-records.json",
|
prof.get_work_hours.should eq 10
|
||||||
)
|
|
||||||
app.get_work_hours.should eq 10
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -17,14 +17,17 @@ module Dayoff
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
class App
|
class Profile
|
||||||
def initialize(pdates_path, wdates_path)
|
PLANNED_DATES = "planned-dates.json"
|
||||||
content = File.open(pdates_path) do |file|
|
WORK_RECORDS = "work-records.json"
|
||||||
|
|
||||||
|
def initialize(@path : String)
|
||||||
|
content = File.open(File.join(@path, PLANNED_DATES)) do |file|
|
||||||
file.gets_to_end
|
file.gets_to_end
|
||||||
end
|
end
|
||||||
@pdates = Array(PlannedDate).from_json(content)
|
@pdates = Array(PlannedDate).from_json(content)
|
||||||
|
|
||||||
content = File.open(wdates_path) do |file|
|
content = File.open(File.join(@path, WORK_RECORDS)) do |file|
|
||||||
file.gets_to_end
|
file.gets_to_end
|
||||||
end
|
end
|
||||||
@wrecords = Array(WorkRecord).from_json(content)
|
@wrecords = Array(WorkRecord).from_json(content)
|
||||||
@ -47,7 +50,13 @@ module Dayoff
|
|||||||
diff = f - s
|
diff = f - s
|
||||||
sum += diff.total_hours.to_i32
|
sum += diff.total_hours.to_i32
|
||||||
end
|
end
|
||||||
return sum
|
sum
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class App
|
||||||
|
def profile(path)
|
||||||
|
Profile.new(path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user