コード例 #1
0
        public string RenderBerlinClock(BerlinClockData berlinClockData)
        {
            if (!berlinClockData.IsValid())
            {
                throw new ArgumentException("Data for rendering are not valid");
            }
            BerlinClockLightRowsRenditions rowsRenditions = ConstructRowsFromData(berlinClockData);
            StringBuilder representationResult            = ConcatRows(rowsRenditions);

            return(representationResult.ToString());
        }
コード例 #2
0
        private static StringBuilder ConcatRows(BerlinClockLightRowsRenditions rowsRenditions)
        {
            const int charsInRepresentation = 40;
            var       representationResult  = new StringBuilder(charsInRepresentation);

            representationResult.AppendLine(rowsRenditions.FirstRow);
            representationResult.AppendLine(rowsRenditions.SecondRow);
            representationResult.AppendLine(rowsRenditions.ThirdRow);
            representationResult.AppendLine(rowsRenditions.FourthRow);
            representationResult.Append(rowsRenditions.FifthRow);
            return(representationResult);
        }
コード例 #3
0
        private BerlinClockLightRowsRenditions ConstructRowsFromData(BerlinClockData berlinClockData)
        {
            var rows = new BerlinClockLightRowsRenditions();

            rows.FirstRow = berlinClockData.IsOneSecondLightActive ? _lightRepresentation.YellowLight.ToString() :
                            _lightRepresentation.Off.ToString();
            rows.SecondRow = CreateLightRow(numberOfActiveLights: berlinClockData.FiveHoursLightsCount,
                                            maxNumberOfLights: BerlinClockDefinition.MaxNumberOfFiveHoursLights,
                                            activeLightRepresentation: _lightRepresentation.RedLight);
            rows.ThirdRow = CreateLightRow(numberOfActiveLights: berlinClockData.OneHourLightsCount,
                                           maxNumberOfLights: BerlinClockDefinition.MaxNumberOfOneHourLights,
                                           activeLightRepresentation: _lightRepresentation.RedLight);
            var tmpFourthRow = CreateLightRow(numberOfActiveLights: berlinClockData.FiveMinutesLightsCount,
                                              maxNumberOfLights: BerlinClockDefinition.MaxNumberOfFiveMinutesLights,
                                              activeLightRepresentation: _lightRepresentation.YellowLight);

            rows.FourthRow = MarkQuarters(aRow: tmpFourthRow,
                                          activeLightRepresentation: _lightRepresentation.YellowLight,
                                          quaterLightRepresentation: _lightRepresentation.RedLight);
            rows.FifthRow = CreateLightRow(numberOfActiveLights: berlinClockData.OneMinuteLightsCount,
                                           maxNumberOfLights: BerlinClockDefinition.MaxNumberOfOneMinuteLights,
                                           activeLightRepresentation: _lightRepresentation.YellowLight);
            return(rows);
        }