Skip to content

Instantly share code, notes, and snippets.

@trekdemo
Last active August 29, 2015 13:57
Show Gist options
  • Save trekdemo/9531868 to your computer and use it in GitHub Desktop.
Save trekdemo/9531868 to your computer and use it in GitHub Desktop.
Y
OOOO
OOOO
OOOOOOOOOOO
OOOO
O
RROO
RRRO
YYROOOOOOOO
YYOO
O
RRRR
RRRO
YYRYYRYYRYY
YYYY
Y
RRRR
RRRR
OOOOOOOOOOO
OOOO
class BerlinUhr
attr_reader :h, :m, :s
def initialize(timestamp)
@timestamp = timestamp
@h, @m, @s= timestamp.split(':').map(&:to_i)
end
def to_s
[seconds, hours, minutes].flatten.join("\n")
end
private
def hours
m, r = h.divmod(5)
[
('R' * m).ljust(4, 'O'),
('R' * r).ljust(4, 'O')
]
end
def minutes
d, r = m.divmod(5)
[
'YYRYYRYYRYY'.slice(0,d).ljust(11, 'O'),
('Y' * r).ljust(4, 'O')
]
end
def seconds
s.even? ? 'Y' : 'O'
end
end
require './berlin_uhr'
describe BerlinUhr do
fixtures = Dir[File.expand_path('../*', __FILE__)].map do |file|
[File.basename(file, '.txt'), File.read(file)]
end
fixtures.each do |time, output|
it "returns the proper output for #{time.inspect}" do
expect(described_class.new(time).to_s).to eq output.strip
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment