Last active
          August 29, 2015 13:57 
        
      - 
      
- 
        Save trekdemo/9531868 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
    
  
  
    
  | Y | |
| OOOO | |
| OOOO | |
| OOOOOOOOOOO | |
| OOOO | 
  
    
      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
    
  
  
    
  | O | |
| RROO | |
| RRRO | |
| YYROOOOOOOO | |
| YYOO | 
  
    
      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
    
  
  
    
  | O | |
| RRRR | |
| RRRO | |
| YYRYYRYYRYY | |
| YYYY | 
  
    
      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
    
  
  
    
  | Y | |
| RRRR | |
| RRRR | |
| OOOOOOOOOOO | |
| OOOO | 
  
    
      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 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 | 
  
    
      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
    
  
  
    
  | 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