Calc work hours

This commit is contained in:
Anton Vakhrushev 2019-11-03 11:57:38 +03:00
parent 3b93c725a3
commit 991396f68c
3 changed files with 42 additions and 6 deletions

14
spec/data/work-dates.json Normal file
View File

@ -0,0 +1,14 @@
[
{
"date": "2019-01-01",
"hours": 10
},
{
"date": "2019-01-02",
"hours": 6
},
{
"date": "2019-01-03",
"hours": 4
}
]

View File

@ -1,9 +1,8 @@
require "./spec_helper" require "./spec_helper"
describe Dayoff do describe Dayoff do
# TODO: Write tests it "can calc work hours" do
app = Dayoff::App.new("./spec/data/work-dates.json")
it "works" do app.get_work_hours.should eq 20
false.should eq(true)
end end
end end

View File

@ -1,6 +1,29 @@
# TODO: Write documentation for `Dayoff` require "json"
module Dayoff module Dayoff
VERSION = "0.1.0" VERSION = "0.1.0"
# TODO: Put your code here class WorkDate
JSON.mapping(
date: String,
hours: Int32,
)
end
class App
def initialize(wh_path)
content = File.open(wh_path) do |file|
file.gets_to_end
end
@wdates = Array(WorkDate).from_json(content)
end
def get_work_hours
sum = 0
@wdates.each do |wd|
sum += wd.hours
end
sum
end
end
end end