hour 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/hour.rb +28 -26
- data/lib/hour/version.rb +1 -1
- metadata +1 -1
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 250f76a57521fe36bc213b0bd6cf7d742c7ecdb4
         | 
| 4 | 
            +
              data.tar.gz: 203bf89298d3827e8197b4d51afbdf48f412f8ec
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: f00705691b427d5f6f6ebe1ea74296a2c8b850b1db85854eaefdd4f9c5913efd6f6ac15c0785aefae202937cdfd8d566edd2356e2d08133bc9207cc0f3784e70
         | 
| 7 | 
            +
              data.tar.gz: 6400d36b10f6e8afb0560017c695d9a28d75806ee05ba1a8f9117ae09b73e61e7990e99929ffd64bf9a456f274dd3caab181da69cf68ccc6bcd707245178e7b6
         | 
    
        data/lib/hour.rb
    CHANGED
    
    | @@ -1,32 +1,34 @@ | |
| 1 1 | 
             
            require "hour/version"
         | 
| 2 2 |  | 
| 3 | 
            -
             | 
| 4 | 
            -
               | 
| 3 | 
            +
            module Hour
         | 
| 4 | 
            +
              class Hour
         | 
| 5 | 
            +
                attr_reader :hours, :minutes, :to_seconds, :to_days, :to_hours_less_days, :to_s, :to_formatted_s, :to_a, :to_time
         | 
| 5 6 |  | 
| 6 | 
            -
             | 
| 7 | 
            -
             | 
| 8 | 
            -
             | 
| 9 | 
            -
             | 
| 10 | 
            -
             | 
| 11 | 
            -
             | 
| 12 | 
            -
             | 
| 13 | 
            -
             | 
| 14 | 
            -
             | 
| 15 | 
            -
             | 
| 16 | 
            -
             | 
| 17 | 
            -
             | 
| 18 | 
            -
             | 
| 19 | 
            -
             | 
| 20 | 
            -
             | 
| 21 | 
            -
             | 
| 22 | 
            -
             | 
| 23 | 
            -
             | 
| 24 | 
            -
             | 
| 25 | 
            -
             | 
| 26 | 
            -
             | 
| 7 | 
            +
                def initialize(hours, minutes = 0)
         | 
| 8 | 
            +
                  hours, minutes = hours.split(':').map(&:to_i) if hours.is_a? String
         | 
| 9 | 
            +
                  minutes = [1, minutes, 59].sort[1] #clamp: constrains the assignment to the middle value
         | 
| 10 | 
            +
                  @to_s = "#{'%02d' % hours}:#{'%02d' % minutes}"
         | 
| 11 | 
            +
                  @to_a = [@hours = hours, @minutes = minutes]
         | 
| 12 | 
            +
                  @to_seconds = ((hours * 60) + minutes) * 60
         | 
| 13 | 
            +
                  @to_days = hours / 24
         | 
| 14 | 
            +
                  @to_hours_less_days = hours - 24 * @to_days
         | 
| 15 | 
            +
                  @to_formatted_s = "#{@to_days} day#{'s' unless @to_days == 1}, " +
         | 
| 16 | 
            +
                                    "#{@to_hours_less_days} hour#{'s' unless @to_hours_less_days == 1}, " +
         | 
| 17 | 
            +
                                    "#{minutes} minute#{'s' unless minutes == 1}"
         | 
| 18 | 
            +
                  @to_time = Time.new(
         | 
| 19 | 
            +
                    0,                   #year
         | 
| 20 | 
            +
                    1,                   #month
         | 
| 21 | 
            +
                    1 + @to_days,        #day
         | 
| 22 | 
            +
                    @to_hours_less_days, #hour
         | 
| 23 | 
            +
                    minutes,             #minute
         | 
| 24 | 
            +
                    0,                   #second
         | 
| 25 | 
            +
                    0                    #UTC    #TODO: gracefully handle both the new Time.zone format and the deprecated UTC
         | 
| 26 | 
            +
                  )
         | 
| 27 | 
            +
                end
         | 
| 27 28 |  | 
| 28 | 
            -
             | 
| 29 | 
            -
             | 
| 30 | 
            -
             | 
| 29 | 
            +
                def self.from_time(time_obj)
         | 
| 30 | 
            +
                  Hour.new(time_obj.hour, time_obj.min)
         | 
| 31 | 
            +
                end
         | 
| 31 32 |  | 
| 33 | 
            +
              end
         | 
| 32 34 | 
             
            end
         | 
    
        data/lib/hour/version.rb
    CHANGED