Created
January 9, 2018 14:18
-
-
Save valterbarros/41190963e07addc56be2862fcfb8447c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Days | |
attr_reader :day, :fck_tests | |
def initialize(day, fck_tests = []) | |
@day = day | |
@fck_tests = fck_tests | |
end | |
end | |
class DaysBuilder | |
FckTest = Struct.new(:id, :fck_tested) | |
def initialize(repo_truck, repo_traceability) | |
@repo_truck = trepo_truck | |
end | |
def build | |
fck_tests_days.map do |day| | |
fck_tests = build_fck_tests(day) | |
Days.new(day, fck_tests) | |
end | |
end | |
def build_fck_tests(day) | |
truck_compression_tests_by_day(day).map { |tc| FckTest.new(id: tc.id, fck_tested: tc.fck_tested) } | |
traceabilty_tests_by_day(day).map { |tc| FckTest.new(id: '', fck_tested: 0.0) } | |
end | |
def truck_compression_tests_by_day(day) | |
@truck_repo.truck_compression_tests.where(day: day) | |
end | |
end | |
def compression_tests | |
compression_tests_params = {} | |
@truck.truck_compression_tests.each do |tct| | |
compression_tests_params[tct.age] ||= [] | |
compression_tests_params[tct.age] << { id: tct.id, fck_tested: tct.fck_tested } | |
end | |
compression_tests_params | |
end | |
def build_days | |
DaysBuilder.new(repo).build() | |
FckTest = Struct.new(:id, :fck_tested) | |
fck_tests_days.map do |day| | |
fck_tests = @truck.truck_compression_tests.where(day: day).map { |tc| FckTest.new(id: tc.id, fck_tested: tc.fck_tested) } | |
Days.new(day, fck_tests) | |
end | |
end | |
build_days = [Days, Days, Days] | |
build_days.each do |b| | |
b.day | |
b.fck_tests.each do |fck_test| | |
fck_test.id | |
fck_test.fck_tested | |
end | |
build_remains_blocks(b.fck_tests.count, max) | |
end | |
def build_remains_blocks(count_fck_tests, max) | |
html = '' | |
1..(max - count_fck_tests) do | |
html << """ | |
<div></div> | |
<div></div> | |
<div></div> | |
""" | |
end | |
html | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment