Add profile class

This commit is contained in:
Anton Vakhrushev 2019-11-03 19:45:48 +03:00
parent 3195a14bb3
commit e9fa65a8f7
3 changed files with 25 additions and 15 deletions

View File

@ -11,3 +11,8 @@ targets:
crystal: 0.31.1
license: MIT
development_dependencies:
ameba:
github: crystal-ameba/ameba
version: ~> 0.10.1

View File

@ -2,18 +2,14 @@ require "./spec_helper"
describe Dayoff do
it "can calc work hours" do
app = Dayoff::App.new(
"./spec/data/planned-dates.json",
"./spec/data/work-records.json",
)
app.get_planned_hours.should eq 20
app = Dayoff::App.new
prof = app.profile("./spec/data")
prof.get_planned_hours.should eq 20
end
it "can calc work hours" do
app = Dayoff::App.new(
"./spec/data/planned-dates.json",
"./spec/data/work-records.json",
)
app.get_work_hours.should eq 10
app = Dayoff::App.new
prof = app.profile("./spec/data")
prof.get_work_hours.should eq 10
end
end

View File

@ -17,14 +17,17 @@ module Dayoff
)
end
class App
def initialize(pdates_path, wdates_path)
content = File.open(pdates_path) do |file|
class Profile
PLANNED_DATES = "planned-dates.json"
WORK_RECORDS = "work-records.json"
def initialize(@path : String)
content = File.open(File.join(@path, PLANNED_DATES)) do |file|
file.gets_to_end
end
@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
end
@wrecords = Array(WorkRecord).from_json(content)
@ -47,7 +50,13 @@ module Dayoff
diff = f - s
sum += diff.total_hours.to_i32
end
return sum
sum
end
end
class App
def profile(path)
Profile.new(path)
end
end
end