Calc work hours
This commit is contained in:
parent
3b93c725a3
commit
991396f68c
14
spec/data/work-dates.json
Normal file
14
spec/data/work-dates.json
Normal file
@ -0,0 +1,14 @@
|
||||
[
|
||||
{
|
||||
"date": "2019-01-01",
|
||||
"hours": 10
|
||||
},
|
||||
{
|
||||
"date": "2019-01-02",
|
||||
"hours": 6
|
||||
},
|
||||
{
|
||||
"date": "2019-01-03",
|
||||
"hours": 4
|
||||
}
|
||||
]
|
@ -1,9 +1,8 @@
|
||||
require "./spec_helper"
|
||||
|
||||
describe Dayoff do
|
||||
# TODO: Write tests
|
||||
|
||||
it "works" do
|
||||
false.should eq(true)
|
||||
it "can calc work hours" do
|
||||
app = Dayoff::App.new("./spec/data/work-dates.json")
|
||||
app.get_work_hours.should eq 20
|
||||
end
|
||||
end
|
||||
|
@ -1,6 +1,29 @@
|
||||
# TODO: Write documentation for `Dayoff`
|
||||
require "json"
|
||||
|
||||
module Dayoff
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user