ice_cube 0.12.0 → 0.12.1
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/ice_cube.rb +0 -1
- data/lib/ice_cube/deprecated.rb +26 -28
- data/lib/ice_cube/parsers/hash_parser.rb +3 -3
- data/lib/ice_cube/parsers/yaml_parser.rb +3 -5
- data/lib/ice_cube/schedule.rb +3 -1
- data/lib/ice_cube/time_util.rb +9 -5
- data/lib/ice_cube/validated_rule.rb +5 -0
- data/lib/ice_cube/validations/daily_interval.rb +2 -2
- data/lib/ice_cube/validations/hourly_interval.rb +2 -2
- data/lib/ice_cube/validations/minutely_interval.rb +2 -2
- data/lib/ice_cube/validations/monthly_interval.rb +2 -2
- data/lib/ice_cube/validations/secondly_interval.rb +2 -2
- data/lib/ice_cube/validations/weekly_interval.rb +2 -2
- data/lib/ice_cube/validations/yearly_interval.rb +3 -2
- data/lib/ice_cube/version.rb +1 -1
- metadata +3 -9
- data/lib/ice_cube/enumerator.rb +0 -63
- data/lib/ice_cube/formatters/string.rb +0 -155
- data/lib/ice_cube/hash_input.rb +0 -71
- data/lib/ice_cube/string_helpers.rb +0 -10
- data/lib/ice_cube/time_step.rb +0 -30
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 2ac4ca18d263a59f5e9499349ce536e63d8ec59f
         | 
| 4 | 
            +
              data.tar.gz: 3d2d4ed0d0cf8c0632b870b19e59ac964d64f93a
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: d6715a91023b1c7c0fa7f1bdc59776c0182b3742bd37a6fc28fd14e0bd15ee5e4d0e2c1014c03c43c04cfaaee8b73ed19d5a7557b815f949fe72d044fb9a61bb
         | 
| 7 | 
            +
              data.tar.gz: f2941f23021a8062fc35cc3f3dd1bd2010903645d723aa9bf7ba3b50a4c240ef88757539c6317b4cab967f7d357a5ccf915d84c963659a97a54d47f5c05efc53
         | 
    
        data/lib/ice_cube.rb
    CHANGED
    
    
    
        data/lib/ice_cube/deprecated.rb
    CHANGED
    
    | @@ -1,38 +1,36 @@ | |
| 1 1 | 
             
            module IceCube
         | 
| 2 | 
            -
             | 
| 2 | 
            +
              module Deprecated
         | 
| 3 3 |  | 
| 4 | 
            -
             | 
| 5 | 
            -
             | 
| 6 | 
            -
             | 
| 7 | 
            -
             | 
| 8 | 
            -
             | 
| 9 | 
            -
             | 
| 10 | 
            -
             | 
| 11 | 
            -
             | 
| 12 | 
            -
             | 
| 13 | 
            -
             | 
| 4 | 
            +
                # Define a deprecated alias for a method
         | 
| 5 | 
            +
                # @param [Symbol] name - name of method to define
         | 
| 6 | 
            +
                # @param [Symbol] replacement - name of method to replace (alias)
         | 
| 7 | 
            +
                def deprecated_alias(name, replacement)
         | 
| 8 | 
            +
                  # Create a wrapped version
         | 
| 9 | 
            +
                  define_method(name) do |*args, &block|
         | 
| 10 | 
            +
                    warn "IceCube: #{self.class}##{name} is deprecated, please use ##{replacement} at: #{ caller[0] }"
         | 
| 11 | 
            +
                    send replacement, *args, &block
         | 
| 12 | 
            +
                  end
         | 
| 13 | 
            +
                end
         | 
| 14 14 |  | 
| 15 | 
            -
             | 
| 16 | 
            -
             | 
| 17 | 
            -
             | 
| 18 | 
            -
             | 
| 19 | 
            -
             | 
| 20 | 
            -
             | 
| 21 | 
            -
             | 
| 22 | 
            -
             | 
| 23 | 
            -
             | 
| 24 | 
            -
             | 
| 25 | 
            -
             | 
| 26 | 
            -
             | 
| 27 | 
            -
             | 
| 15 | 
            +
                # Deprecate a defined method
         | 
| 16 | 
            +
                # @param [Symbol] name - name of deprecated method
         | 
| 17 | 
            +
                # @param [Symbol] replacement - name of the desired replacement
         | 
| 18 | 
            +
                def deprecated(name, replacement)
         | 
| 19 | 
            +
                  # Replace old method
         | 
| 20 | 
            +
                  old_name = :"#{name}_without_deprecation"
         | 
| 21 | 
            +
                  alias_method old_name, name
         | 
| 22 | 
            +
                  # And replace it with a wrapped version
         | 
| 23 | 
            +
                  define_method(name) do |*args, &block|
         | 
| 24 | 
            +
                    warn "IceCube: #{self.class}##{name} is deprecated, please use ##{replacement} at: #{ caller[0] }"
         | 
| 25 | 
            +
                    send old_name, *args, &block
         | 
| 26 | 
            +
                  end
         | 
| 27 | 
            +
                end
         | 
| 28 28 |  | 
| 29 29 | 
             
                def self.schedule_options(schedule, options)
         | 
| 30 30 | 
             
                  if options[:start_date_override]
         | 
| 31 | 
            -
                    warn "IceCube: :start_date_override option deprecated. " | 
| 32 | 
            -
                      "(please use a block { |s| s.start_time = override })"
         | 
| 31 | 
            +
                    warn "IceCube: :start_date_override option is deprecated, please use a block {|s| s.start_time = override }. at: #{ caller[0] }"
         | 
| 33 32 | 
             
                    schedule.start_time = options[:start_date_override]
         | 
| 34 33 | 
             
                  end
         | 
| 35 34 | 
             
                end
         | 
| 36 | 
            -
             | 
| 37 | 
            -
            	end
         | 
| 35 | 
            +
              end
         | 
| 38 36 | 
             
            end
         | 
| @@ -26,13 +26,13 @@ module IceCube | |
| 26 26 | 
             
                  data = IceCube::FlexibleHash.new(hash.dup)
         | 
| 27 27 |  | 
| 28 28 | 
             
                  if (start_date = data.delete(:start_date))
         | 
| 29 | 
            -
             | 
| 29 | 
            +
                    warn "IceCube: :start_date is deprecated, please use :start_time at: #{ caller[0] }"
         | 
| 30 30 | 
             
                    data[:start_time] = start_date
         | 
| 31 31 | 
             
                  end
         | 
| 32 32 |  | 
| 33 33 | 
             
                  {:rdates => :rtimes, :exdates => :extimes}.each do |old_key, new_key|
         | 
| 34 34 | 
             
                    if (times = data.delete(old_key))
         | 
| 35 | 
            -
                      warn "IceCube: :#{old_key} deprecated | 
| 35 | 
            +
                      warn "IceCube: :#{old_key} is deprecated, please use :#{new_key} at: #{ caller[0] }"
         | 
| 36 36 | 
             
                      (data[new_key] ||= []).concat times
         | 
| 37 37 | 
             
                    end
         | 
| 38 38 | 
             
                  end
         | 
| @@ -59,7 +59,7 @@ module IceCube | |
| 59 59 |  | 
| 60 60 | 
             
                def apply_exrules(schedule, data)
         | 
| 61 61 | 
             
                  return unless data[:exrules]
         | 
| 62 | 
            -
                  warn "IceCube: :exrules deprecated | 
| 62 | 
            +
                  warn "IceCube: :exrules is deprecated, and will be removed in a future release. at: #{ caller[0] }"
         | 
| 63 63 | 
             
                  data[:exrules].each do |h|
         | 
| 64 64 | 
             
                    schedule.exrule(IceCube::Rule.from_hash(h))
         | 
| 65 65 | 
             
                  end
         | 
| @@ -1,3 +1,5 @@ | |
| 1 | 
            +
            require 'yaml'
         | 
| 2 | 
            +
             | 
| 1 3 | 
             
            module IceCube
         | 
| 2 4 | 
             
              class YamlParser < HashParser
         | 
| 3 5 |  | 
| @@ -7,15 +9,11 @@ module IceCube | |
| 7 9 |  | 
| 8 10 | 
             
                def initialize(yaml)
         | 
| 9 11 | 
             
                  @hash = YAML::load(yaml)
         | 
| 10 | 
            -
                  yaml.match | 
| 12 | 
            +
                  yaml.match SERIALIZED_START do |match|
         | 
| 11 13 | 
             
                    start_time = hash[:start_time] || hash[:start_date]
         | 
| 12 | 
            -
                    hash = FlexibleHash.new(@hash)
         | 
| 13 14 | 
             
                    TimeUtil.restore_deserialized_offset start_time, match[:tz]
         | 
| 14 15 | 
             
                  end
         | 
| 15 16 | 
             
                end
         | 
| 16 17 |  | 
| 17 | 
            -
                private
         | 
| 18 | 
            -
             | 
| 19 | 
            -
             | 
| 20 18 | 
             
              end
         | 
| 21 19 | 
             
            end
         | 
    
        data/lib/ice_cube/schedule.rb
    CHANGED
    
    | @@ -380,11 +380,13 @@ module IceCube | |
| 380 380 | 
             
                end
         | 
| 381 381 |  | 
| 382 382 | 
             
                def self.dump(schedule)
         | 
| 383 | 
            +
                  return schedule if schedule.nil? || schedule == ""
         | 
| 383 384 | 
             
                  schedule.to_yaml
         | 
| 384 385 | 
             
                end
         | 
| 385 386 |  | 
| 386 387 | 
             
                def self.load(yaml)
         | 
| 387 | 
            -
                   | 
| 388 | 
            +
                  return yaml if yaml.nil? || yaml == ""
         | 
| 389 | 
            +
                  from_yaml(yaml)
         | 
| 388 390 | 
             
                end
         | 
| 389 391 |  | 
| 390 392 | 
             
                private
         | 
    
        data/lib/ice_cube/time_util.rb
    CHANGED
    
    | @@ -1,4 +1,5 @@ | |
| 1 1 | 
             
            require 'date'
         | 
| 2 | 
            +
            require 'time'
         | 
| 2 3 |  | 
| 3 4 | 
             
            module IceCube
         | 
| 4 5 | 
             
              module TimeUtil
         | 
| @@ -42,7 +43,7 @@ module IceCube | |
| 42 43 | 
             
                def self.ensure_time(time, date_eod = false)
         | 
| 43 44 | 
             
                  case time
         | 
| 44 45 | 
             
                  when DateTime
         | 
| 45 | 
            -
                    warn "IceCube: DateTime support is deprecated (please use Time)"
         | 
| 46 | 
            +
                    warn "IceCube: DateTime support is deprecated (please use Time) at: #{ caller[2] }"
         | 
| 46 47 | 
             
                    Time.local(time.year, time.month, time.day, time.hour, time.min, time.sec)
         | 
| 47 48 | 
             
                  when Date
         | 
| 48 49 | 
             
                    date_eod ? end_of_date(time) : time.to_time
         | 
| @@ -69,13 +70,16 @@ module IceCube | |
| 69 70 | 
             
                  end
         | 
| 70 71 | 
             
                end
         | 
| 71 72 |  | 
| 72 | 
            -
                # Deserialize a time serialized with serialize_time
         | 
| 73 | 
            +
                # Deserialize a time serialized with serialize_time or in ISO8601 string format
         | 
| 73 74 | 
             
                def self.deserialize_time(time_or_hash)
         | 
| 74 | 
            -
                   | 
| 75 | 
            +
                  case time_or_hash
         | 
| 76 | 
            +
                  when Time
         | 
| 75 77 | 
             
                    time_or_hash
         | 
| 76 | 
            -
                   | 
| 78 | 
            +
                  when Hash
         | 
| 77 79 | 
             
                    hash = FlexibleHash.new(time_or_hash)
         | 
| 78 80 | 
             
                    hash[:time].in_time_zone(hash[:zone])
         | 
| 81 | 
            +
                  when String
         | 
| 82 | 
            +
                    Time.parse(time_or_hash)
         | 
| 79 83 | 
             
                  end
         | 
| 80 84 | 
             
                end
         | 
| 81 85 |  | 
| @@ -87,7 +91,7 @@ module IceCube | |
| 87 91 | 
             
                def self.restore_deserialized_offset(time, orig_offset_str)
         | 
| 88 92 | 
             
                  return time if time.respond_to?(:time_zone) ||
         | 
| 89 93 | 
             
                                 time.getlocal(orig_offset_str).utc_offset == time.utc_offset
         | 
| 90 | 
            -
                  warn  | 
| 94 | 
            +
                  warn "IceCube: parsed Time from nonlocal TZ. Use ActiveSupport to fix DST at: #{ caller[0] }"
         | 
| 91 95 | 
             
                  time.localtime(orig_offset_str)
         | 
| 92 96 | 
             
                end
         | 
| 93 97 |  | 
| @@ -106,6 +106,11 @@ module IceCube | |
| 106 106 | 
             
                end
         | 
| 107 107 |  | 
| 108 108 | 
             
                private
         | 
| 109 | 
            +
                def normalized_interval(interval)
         | 
| 110 | 
            +
                  int = interval.to_i
         | 
| 111 | 
            +
                  raise ArgumentError, "'#{interval}' is not a valid input for interval. Please pass an integer." unless int > 0
         | 
| 112 | 
            +
                  int
         | 
| 113 | 
            +
                end
         | 
| 109 114 |  | 
| 110 115 | 
             
                def finds_acceptable_time?
         | 
| 111 116 | 
             
                  validation_names.all? do |type|
         | 
| @@ -4,8 +4,8 @@ module IceCube | |
| 4 4 |  | 
| 5 5 | 
             
                # Add a new interval validation
         | 
| 6 6 | 
             
                def interval(interval)
         | 
| 7 | 
            -
                  @interval = interval
         | 
| 8 | 
            -
                  replace_validations_for(:interval, [Validation.new(interval)])
         | 
| 7 | 
            +
                  @interval = normalized_interval(interval)
         | 
| 8 | 
            +
                  replace_validations_for(:interval, [Validation.new(@interval)])
         | 
| 9 9 | 
             
                  clobber_base_validations(:wday, :day)
         | 
| 10 10 | 
             
                  self
         | 
| 11 11 | 
             
                end
         | 
| @@ -3,8 +3,8 @@ module IceCube | |
| 3 3 | 
             
              module Validations::HourlyInterval
         | 
| 4 4 |  | 
| 5 5 | 
             
                def interval(interval)
         | 
| 6 | 
            -
                  @interval = interval
         | 
| 7 | 
            -
                  replace_validations_for(:interval, [Validation.new(interval)])
         | 
| 6 | 
            +
                  @interval = normalized_interval(interval)
         | 
| 7 | 
            +
                  replace_validations_for(:interval, [Validation.new(@interval)])
         | 
| 8 8 | 
             
                  clobber_base_validations(:hour)
         | 
| 9 9 | 
             
                  self
         | 
| 10 10 | 
             
                end
         | 
| @@ -3,8 +3,8 @@ module IceCube | |
| 3 3 | 
             
              module Validations::MinutelyInterval
         | 
| 4 4 |  | 
| 5 5 | 
             
                def interval(interval)
         | 
| 6 | 
            -
                  @interval = interval
         | 
| 7 | 
            -
                  replace_validations_for(:interval, [Validation.new(interval)])
         | 
| 6 | 
            +
                  @interval = normalized_interval(interval)
         | 
| 7 | 
            +
                  replace_validations_for(:interval, [Validation.new(@interval)])
         | 
| 8 8 | 
             
                  clobber_base_validations(:min)
         | 
| 9 9 | 
             
                  self
         | 
| 10 10 | 
             
                end
         | 
| @@ -3,8 +3,8 @@ module IceCube | |
| 3 3 | 
             
              module Validations::MonthlyInterval
         | 
| 4 4 |  | 
| 5 5 | 
             
                def interval(interval)
         | 
| 6 | 
            -
                  @interval = interval
         | 
| 7 | 
            -
                  replace_validations_for(:interval, [Validation.new(interval)])
         | 
| 6 | 
            +
                  @interval = normalized_interval(interval)
         | 
| 7 | 
            +
                  replace_validations_for(:interval, [Validation.new(@interval)])
         | 
| 8 8 | 
             
                  clobber_base_validations(:month)
         | 
| 9 9 | 
             
                  self
         | 
| 10 10 | 
             
                end
         | 
| @@ -3,8 +3,8 @@ module IceCube | |
| 3 3 | 
             
              module Validations::SecondlyInterval
         | 
| 4 4 |  | 
| 5 5 | 
             
                def interval(interval)
         | 
| 6 | 
            -
                  @interval = interval
         | 
| 7 | 
            -
                  replace_validations_for(:interval, [Validation.new(interval)])
         | 
| 6 | 
            +
                  @interval = normalized_interval(interval)
         | 
| 7 | 
            +
                  replace_validations_for(:interval, [Validation.new(@interval)])
         | 
| 8 8 | 
             
                  clobber_base_validations(:sec)
         | 
| 9 9 | 
             
                  self
         | 
| 10 10 | 
             
                end
         | 
| @@ -5,9 +5,9 @@ module IceCube | |
| 5 5 | 
             
              module Validations::WeeklyInterval
         | 
| 6 6 |  | 
| 7 7 | 
             
                def interval(interval, week_start = :sunday)
         | 
| 8 | 
            -
                  @interval = interval
         | 
| 8 | 
            +
                  @interval = normalized_interval(interval)
         | 
| 9 9 | 
             
                  @week_start = TimeUtil.wday_to_sym(week_start)
         | 
| 10 | 
            -
                  replace_validations_for(:interval, [Validation.new(interval, week_start)])
         | 
| 10 | 
            +
                  replace_validations_for(:interval, [Validation.new(@interval, week_start)])
         | 
| 11 11 | 
             
                  clobber_base_validations(:day)
         | 
| 12 12 | 
             
                  self
         | 
| 13 13 | 
             
                end
         | 
| @@ -3,9 +3,10 @@ module IceCube | |
| 3 3 | 
             
              module Validations::YearlyInterval
         | 
| 4 4 |  | 
| 5 5 | 
             
                def interval(interval)
         | 
| 6 | 
            -
                  @interval = interval
         | 
| 7 | 
            -
                  replace_validations_for(:interval, [Validation.new(interval)])
         | 
| 6 | 
            +
                  @interval = normalized_interval(interval)
         | 
| 7 | 
            +
                  replace_validations_for(:interval, [Validation.new(@interval)])
         | 
| 8 8 | 
             
                  clobber_base_validations(:year)
         | 
| 9 | 
            +
                  self
         | 
| 9 10 | 
             
                end
         | 
| 10 11 |  | 
| 11 12 | 
             
                class Validation
         | 
    
        data/lib/ice_cube/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: ice_cube
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.12. | 
| 4 | 
            +
              version: 0.12.1
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - John Crepezzi
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2014-04 | 
| 11 | 
            +
            date: 2014-07-04 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: rake
         | 
| @@ -39,7 +39,7 @@ dependencies: | |
| 39 39 | 
             
                  - !ruby/object:Gem::Version
         | 
| 40 40 | 
             
                    version: 2.12.0
         | 
| 41 41 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 42 | 
            -
              name:  | 
| 42 | 
            +
              name: activesupport
         | 
| 43 43 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 44 44 | 
             
                requirements:
         | 
| 45 45 | 
             
                - - ">="
         | 
| @@ -78,12 +78,9 @@ files: | |
| 78 78 | 
             
            - lib/ice_cube/builders/ical_builder.rb
         | 
| 79 79 | 
             
            - lib/ice_cube/builders/string_builder.rb
         | 
| 80 80 | 
             
            - lib/ice_cube/deprecated.rb
         | 
| 81 | 
            -
            - lib/ice_cube/enumerator.rb
         | 
| 82 81 | 
             
            - lib/ice_cube/errors/count_exceeded.rb
         | 
| 83 82 | 
             
            - lib/ice_cube/errors/until_exceeded.rb
         | 
| 84 83 | 
             
            - lib/ice_cube/flexible_hash.rb
         | 
| 85 | 
            -
            - lib/ice_cube/formatters/string.rb
         | 
| 86 | 
            -
            - lib/ice_cube/hash_input.rb
         | 
| 87 84 | 
             
            - lib/ice_cube/occurrence.rb
         | 
| 88 85 | 
             
            - lib/ice_cube/parsers/hash_parser.rb
         | 
| 89 86 | 
             
            - lib/ice_cube/parsers/yaml_parser.rb
         | 
| @@ -97,8 +94,6 @@ files: | |
| 97 94 | 
             
            - lib/ice_cube/rules/yearly_rule.rb
         | 
| 98 95 | 
             
            - lib/ice_cube/schedule.rb
         | 
| 99 96 | 
             
            - lib/ice_cube/single_occurrence_rule.rb
         | 
| 100 | 
            -
            - lib/ice_cube/string_helpers.rb
         | 
| 101 | 
            -
            - lib/ice_cube/time_step.rb
         | 
| 102 97 | 
             
            - lib/ice_cube/time_util.rb
         | 
| 103 98 | 
             
            - lib/ice_cube/validated_rule.rb
         | 
| 104 99 | 
             
            - lib/ice_cube/validations/count.rb
         | 
| @@ -148,4 +143,3 @@ specification_version: 4 | |
| 148 143 | 
             
            summary: Ruby Date Recurrence Library
         | 
| 149 144 | 
             
            test_files:
         | 
| 150 145 | 
             
            - spec/spec_helper.rb
         | 
| 151 | 
            -
            has_rdoc: true
         | 
    
        data/lib/ice_cube/enumerator.rb
    DELETED
    
    | @@ -1,63 +0,0 @@ | |
| 1 | 
            -
            module IceCube
         | 
| 2 | 
            -
              class Enumerator < ::Enumerator
         | 
| 3 | 
            -
             | 
| 4 | 
            -
                def initialize(schedule, from_time, to_time)
         | 
| 5 | 
            -
                  @schedule  = schedule
         | 
| 6 | 
            -
                  @from_time = TimeUtil.ensure_time(from_time)
         | 
| 7 | 
            -
                  @to_time   = TimeUtil.ensure_time(to_time)
         | 
| 8 | 
            -
                  align_start_time
         | 
| 9 | 
            -
                  @cursor = @from_time
         | 
| 10 | 
            -
                end
         | 
| 11 | 
            -
             | 
| 12 | 
            -
                def each
         | 
| 13 | 
            -
                  while res = self.find_next && @to_time.nil? || res <= @to_time
         | 
| 14 | 
            -
                    yield Occurrence.new(res, res + schedule.duration)
         | 
| 15 | 
            -
                  end
         | 
| 16 | 
            -
                  raise StopIteration
         | 
| 17 | 
            -
                end
         | 
| 18 | 
            -
             | 
| 19 | 
            -
                def find_next
         | 
| 20 | 
            -
                  loop do
         | 
| 21 | 
            -
                    min_time = recurrence_rules.reduce(nil) do |min_time, rule|
         | 
| 22 | 
            -
                      catch :limit do
         | 
| 23 | 
            -
                        new_time = rule.next_time(time, schedule, min_time || @to_time)
         | 
| 24 | 
            -
                        [min_time, new_time].compact.min
         | 
| 25 | 
            -
                      end
         | 
| 26 | 
            -
                    end
         | 
| 27 | 
            -
                    break nil unless min_time
         | 
| 28 | 
            -
                    @cursor = min_time + 1
         | 
| 29 | 
            -
                    next if exception_time?(min_time)
         | 
| 30 | 
            -
                    break min_time
         | 
| 31 | 
            -
                  end
         | 
| 32 | 
            -
                end
         | 
| 33 | 
            -
             | 
| 34 | 
            -
                private
         | 
| 35 | 
            -
             | 
| 36 | 
            -
                def align_start_time
         | 
| 37 | 
            -
                  if @from_time <= schedule.start_time || full_required?
         | 
| 38 | 
            -
                    @from_time = schedule.start_time
         | 
| 39 | 
            -
                  else
         | 
| 40 | 
            -
                    @from_time += @schedule.start_time.subsec - @from_time.subsec rescue 0
         | 
| 41 | 
            -
                  end
         | 
| 42 | 
            -
                end
         | 
| 43 | 
            -
             | 
| 44 | 
            -
                # Return a boolean indicating if any rule needs to be run from the start of time
         | 
| 45 | 
            -
                def full_required?
         | 
| 46 | 
            -
                  recurrence_rules.any?(&:full_required?) ||
         | 
| 47 | 
            -
                  exception_rules.any?(&:full_required?)
         | 
| 48 | 
            -
                end
         | 
| 49 | 
            -
             | 
| 50 | 
            -
                def exception_rules
         | 
| 51 | 
            -
                  schedule.instance_variable_get(:@all_exception_rules)
         | 
| 52 | 
            -
                end
         | 
| 53 | 
            -
             | 
| 54 | 
            -
                def recurrence_rules
         | 
| 55 | 
            -
                  @recurrence_rules ||= if recurrence_rules.empty?
         | 
| 56 | 
            -
                    [SingleOccurrenceRule.new(schedule.start_time)].concat schedule.instance_variable_get(:@all_recurrence_rules)
         | 
| 57 | 
            -
                  else
         | 
| 58 | 
            -
                    schedule.instance_variable_get(:@all_recurrence_rules)
         | 
| 59 | 
            -
                  end
         | 
| 60 | 
            -
                end
         | 
| 61 | 
            -
             | 
| 62 | 
            -
              end
         | 
| 63 | 
            -
            end
         | 
| @@ -1,155 +0,0 @@ | |
| 1 | 
            -
            class IceCube::StringBuilder
         | 
| 2 | 
            -
             | 
| 3 | 
            -
              format :day do |entries|
         | 
| 4 | 
            -
                case entries = entries.sort
         | 
| 5 | 
            -
                when [0, 6]          then 'on Weekends'
         | 
| 6 | 
            -
                when [1, 2, 3, 4, 5] then 'on Weekdays'
         | 
| 7 | 
            -
                else
         | 
| 8 | 
            -
                  "on " << build(:sentence, build(:daynames, entries))
         | 
| 9 | 
            -
                end
         | 
| 10 | 
            -
              end
         | 
| 11 | 
            -
             | 
| 12 | 
            -
              format :dayname do |number|
         | 
| 13 | 
            -
                Date::DAYNAMES[number]
         | 
| 14 | 
            -
              end
         | 
| 15 | 
            -
             | 
| 16 | 
            -
              format :daynames do |entries|
         | 
| 17 | 
            -
                entries.map { |wday| build(:dayname, wday) + "s" }
         | 
| 18 | 
            -
              end
         | 
| 19 | 
            -
             | 
| 20 | 
            -
              format :monthnames do |entries|
         | 
| 21 | 
            -
                entries.map { |m| Date::MONTHNAMES[m] }
         | 
| 22 | 
            -
              end
         | 
| 23 | 
            -
             | 
| 24 | 
            -
              format :count do |number|
         | 
| 25 | 
            -
                times = number == 1 ? "time" : "times"
         | 
| 26 | 
            -
                "#{number} #{times}"
         | 
| 27 | 
            -
              end
         | 
| 28 | 
            -
             | 
| 29 | 
            -
              format :day_of_month do |entries|
         | 
| 30 | 
            -
                numbered = build(:sentence, build(:ordinals, entries))
         | 
| 31 | 
            -
                days = entries.size == 1 ? "day" : "days"
         | 
| 32 | 
            -
                "on the #{numbered} #{days} of the month"
         | 
| 33 | 
            -
              end
         | 
| 34 | 
            -
             | 
| 35 | 
            -
              format :day_of_week do |entries|
         | 
| 36 | 
            -
                numbered_weekdays = build(:daynames_of_week, entries).join(" and ")
         | 
| 37 | 
            -
                "on the #{numbered_weekdays}"
         | 
| 38 | 
            -
              end
         | 
| 39 | 
            -
             | 
| 40 | 
            -
              format :daynames_of_week do |entries|
         | 
| 41 | 
            -
                entries.map do |occurrence, wday|
         | 
| 42 | 
            -
                  numbered = build(:ordinal, occurrence)
         | 
| 43 | 
            -
                  weekday  = build(:dayname, wday)
         | 
| 44 | 
            -
                  "#{numbered} #{weekday}"
         | 
| 45 | 
            -
                end
         | 
| 46 | 
            -
              end
         | 
| 47 | 
            -
             | 
| 48 | 
            -
              format :day_of_year do |entries|
         | 
| 49 | 
            -
                numbered = build(:sentence, build(:ordinals, entries))
         | 
| 50 | 
            -
                days = entries.size == 1 ? "day" : "days"
         | 
| 51 | 
            -
                "on the #{numbered} #{days} of the year"
         | 
| 52 | 
            -
              end
         | 
| 53 | 
            -
             | 
| 54 | 
            -
              format :hour_of_day do |entries|
         | 
| 55 | 
            -
                numbered = build(:sentence, build(:ordinals, entries))
         | 
| 56 | 
            -
                hours = entries.size == 1 ? "hour" : "hours"
         | 
| 57 | 
            -
                "on the #{numbered} #{hours} of the day"
         | 
| 58 | 
            -
              end
         | 
| 59 | 
            -
             | 
| 60 | 
            -
              format :minute_of_hour do |entries|
         | 
| 61 | 
            -
                numbered = build(:sentence, build(:ordinals, entries))
         | 
| 62 | 
            -
                minutes = entries.size == 1 ? "minute" : "minutes"
         | 
| 63 | 
            -
                "on the #{numbered} #{minutes} of the hour"
         | 
| 64 | 
            -
              end
         | 
| 65 | 
            -
             | 
| 66 | 
            -
              format :month_of_year do |entries|
         | 
| 67 | 
            -
                "in " << build(:sentence, build(:monthnames, entries))
         | 
| 68 | 
            -
              end
         | 
| 69 | 
            -
             | 
| 70 | 
            -
              format :second_of_minute do |entries|
         | 
| 71 | 
            -
                numbered = build(:sentence, build(:ordinals, entries))
         | 
| 72 | 
            -
                seconds = entries.size == 1 ? "second" : "seconds"
         | 
| 73 | 
            -
                "on the #{numbered} #{seconds} of the minute"
         | 
| 74 | 
            -
              end
         | 
| 75 | 
            -
             | 
| 76 | 
            -
              format :time do |time|
         | 
| 77 | 
            -
                time.strftime(IceCube.to_s_time_format)
         | 
| 78 | 
            -
              end
         | 
| 79 | 
            -
             | 
| 80 | 
            -
              format :until do |time|
         | 
| 81 | 
            -
                "until " << build(:time, time)
         | 
| 82 | 
            -
              end
         | 
| 83 | 
            -
             | 
| 84 | 
            -
              format :sentence do |entries|
         | 
| 85 | 
            -
                case entries.length
         | 
| 86 | 
            -
                when 0 then ''
         | 
| 87 | 
            -
                when 1 then entries[0].to_s
         | 
| 88 | 
            -
                when 2 then "#{entries[0]} and #{entries[1]}"
         | 
| 89 | 
            -
                else "#{entries[0...-1].join(', ')}, and #{entries[-1]}"
         | 
| 90 | 
            -
                end
         | 
| 91 | 
            -
              end
         | 
| 92 | 
            -
             | 
| 93 | 
            -
              format :ordinals do |entries|
         | 
| 94 | 
            -
                entries = entries.sort
         | 
| 95 | 
            -
                entries.rotate! while entries[0] < 0 if entries.last > 0
         | 
| 96 | 
            -
                entries.map { |number| build(:ordinal, number) }
         | 
| 97 | 
            -
              end
         | 
| 98 | 
            -
             | 
| 99 | 
            -
              format :ordinal do |number|
         | 
| 100 | 
            -
                next "last" if number == -1
         | 
| 101 | 
            -
                suffix = SPECIAL_SUFFIX[number] || NUMBER_SUFFIX[number.abs % 10]
         | 
| 102 | 
            -
                if number < -1
         | 
| 103 | 
            -
                  number.abs.to_s << suffix << " to last"
         | 
| 104 | 
            -
                else
         | 
| 105 | 
            -
                  number.to_s << suffix
         | 
| 106 | 
            -
                end
         | 
| 107 | 
            -
              end
         | 
| 108 | 
            -
             | 
| 109 | 
            -
              format :daily_interval do |i|
         | 
| 110 | 
            -
                i == 1 ? "Daily" : "Every #{i} days"
         | 
| 111 | 
            -
              end
         | 
| 112 | 
            -
             | 
| 113 | 
            -
              format :hourly_interval do |i|
         | 
| 114 | 
            -
                i == 1 ? "Hourly" : "Every #{i} hours"
         | 
| 115 | 
            -
              end
         | 
| 116 | 
            -
             | 
| 117 | 
            -
              format :minutely_interval do |i|
         | 
| 118 | 
            -
                i == 1 ? "Minutely" : "Every #{i} minutes"
         | 
| 119 | 
            -
              end
         | 
| 120 | 
            -
             | 
| 121 | 
            -
              format :monthly_interval do |i|
         | 
| 122 | 
            -
                i == 1 ? "Monthly" : "Every #{i} months"
         | 
| 123 | 
            -
              end
         | 
| 124 | 
            -
             | 
| 125 | 
            -
              format :secondly_interval do |i|
         | 
| 126 | 
            -
                i == 1 ? "Secondly" : "Every #{i} seconds"
         | 
| 127 | 
            -
              end
         | 
| 128 | 
            -
             | 
| 129 | 
            -
              format :weekly_interval do |i|
         | 
| 130 | 
            -
                i == 1 ? "Weekly" : "Every #{i} weeks"
         | 
| 131 | 
            -
              end
         | 
| 132 | 
            -
             | 
| 133 | 
            -
              format :yearly_interval do |i|
         | 
| 134 | 
            -
                i == 1 ? "Yearly" : "Every #{i} years"
         | 
| 135 | 
            -
              end
         | 
| 136 | 
            -
             | 
| 137 | 
            -
              format :exrule do |rule|
         | 
| 138 | 
            -
                "not #{rule}"
         | 
| 139 | 
            -
              end
         | 
| 140 | 
            -
             | 
| 141 | 
            -
              format :extime do |time|
         | 
| 142 | 
            -
                "not on #{build(:time, time)}"
         | 
| 143 | 
            -
              end
         | 
| 144 | 
            -
             | 
| 145 | 
            -
              format :schedule do |s|
         | 
| 146 | 
            -
                times = s.recurrence_times_with_start_time - s.extimes
         | 
| 147 | 
            -
                pieces = []
         | 
| 148 | 
            -
                pieces.concat times.uniq.sort.map     { |t| build(:time, t) }
         | 
| 149 | 
            -
                pieces.concat s.rrules.map            { |t| t.to_s }
         | 
| 150 | 
            -
                pieces.concat s.exrules.map           { |t| build(:exrule, t) }
         | 
| 151 | 
            -
                pieces.concat s.extimes.uniq.sort.map { |t| build(:extime, t) }
         | 
| 152 | 
            -
                pieces.join(' / ')
         | 
| 153 | 
            -
              end
         | 
| 154 | 
            -
             | 
| 155 | 
            -
            end
         | 
    
        data/lib/ice_cube/hash_input.rb
    DELETED
    
    | @@ -1,71 +0,0 @@ | |
| 1 | 
            -
            module IceCube
         | 
| 2 | 
            -
              class HashInput
         | 
| 3 | 
            -
             | 
| 4 | 
            -
                class Mash
         | 
| 5 | 
            -
                  def initialize(hash)
         | 
| 6 | 
            -
                    @hash = hash
         | 
| 7 | 
            -
                  end
         | 
| 8 | 
            -
             | 
| 9 | 
            -
                  # Fetch values indifferently by symbol or string key without symbolizing
         | 
| 10 | 
            -
                  # arbitrary string input
         | 
| 11 | 
            -
                  #
         | 
| 12 | 
            -
                  def [](key)
         | 
| 13 | 
            -
                    @hash.fetch(key) do |key|
         | 
| 14 | 
            -
                      str_key = key.to_s
         | 
| 15 | 
            -
                      @hash.each_pair.detect do |sym_key, value|
         | 
| 16 | 
            -
                        return value if sym_key.to_s == str_key
         | 
| 17 | 
            -
                      end
         | 
| 18 | 
            -
                    end
         | 
| 19 | 
            -
                  end
         | 
| 20 | 
            -
                end
         | 
| 21 | 
            -
             | 
| 22 | 
            -
                def initialize(hash)
         | 
| 23 | 
            -
                  @input = Mash.new(hash)
         | 
| 24 | 
            -
                end
         | 
| 25 | 
            -
             | 
| 26 | 
            -
                def [](key)
         | 
| 27 | 
            -
                  @input[key]
         | 
| 28 | 
            -
                end
         | 
| 29 | 
            -
             | 
| 30 | 
            -
                def to_rule
         | 
| 31 | 
            -
                  return nil unless rule_class
         | 
| 32 | 
            -
                  rule = rule_class.new(interval, week_start)
         | 
| 33 | 
            -
                  rule.until(limit_time) if limit_time
         | 
| 34 | 
            -
                  rule.count(limit_count) if limit_count
         | 
| 35 | 
            -
                  validations.each do |validation, args|
         | 
| 36 | 
            -
                    rule.send(validation, *args)
         | 
| 37 | 
            -
                  end
         | 
| 38 | 
            -
                end
         | 
| 39 | 
            -
             | 
| 40 | 
            -
                def rule_class
         | 
| 41 | 
            -
                  return @rule_class if @rule_class
         | 
| 42 | 
            -
                  match = @input[:rule_type].match(/::(\w+Rule)$/)
         | 
| 43 | 
            -
                  @rule_class = IceCube.const_get(match[1]) if match
         | 
| 44 | 
            -
                end
         | 
| 45 | 
            -
             | 
| 46 | 
            -
                def interval
         | 
| 47 | 
            -
                  @input[:interval] || 1
         | 
| 48 | 
            -
                end
         | 
| 49 | 
            -
             | 
| 50 | 
            -
                def week_start
         | 
| 51 | 
            -
                  @input[:week_start] || :sunday
         | 
| 52 | 
            -
                end
         | 
| 53 | 
            -
             | 
| 54 | 
            -
                def limit_time
         | 
| 55 | 
            -
                  @limit_time ||= TimeUtil.deserialize_time(@input[:until])
         | 
| 56 | 
            -
                end
         | 
| 57 | 
            -
             | 
| 58 | 
            -
                def limit_count
         | 
| 59 | 
            -
                  @input[:count]
         | 
| 60 | 
            -
                end
         | 
| 61 | 
            -
             | 
| 62 | 
            -
                def validations
         | 
| 63 | 
            -
                  input_validations = Mash.new(@input[:validations] || {})
         | 
| 64 | 
            -
                  ValidatedRule::VALIDATION_ORDER.each_with_object({}) do |key, output_validations|
         | 
| 65 | 
            -
                    args = input_validations[key]
         | 
| 66 | 
            -
                    output_validations[key] = Array(args) if args
         | 
| 67 | 
            -
                  end
         | 
| 68 | 
            -
                end
         | 
| 69 | 
            -
             | 
| 70 | 
            -
              end
         | 
| 71 | 
            -
            end
         | 
    
        data/lib/ice_cube/time_step.rb
    DELETED
    
    | @@ -1,30 +0,0 @@ | |
| 1 | 
            -
            module IceCube
         | 
| 2 | 
            -
              class TimeStep
         | 
| 3 | 
            -
                SECS   = 1
         | 
| 4 | 
            -
                MINS   = 60
         | 
| 5 | 
            -
                HOURS  = MINS * 60
         | 
| 6 | 
            -
                DAYS   = HOURS * 24
         | 
| 7 | 
            -
                WEEKS  = DAYS * 7
         | 
| 8 | 
            -
                MONTHS = {
         | 
| 9 | 
            -
                  1  => [ 28,  29,  30,  31].map { |m| m * DAYS },
         | 
| 10 | 
            -
                  2  => [ 59,  60,  61,  62].map { |m| m * DAYS },
         | 
| 11 | 
            -
                  3  => [ 89,  90,  91,  92].map { |m| m * DAYS },
         | 
| 12 | 
            -
                  4  => [120, 121, 122, 123].map { |m| m * DAYS },
         | 
| 13 | 
            -
                  5  => [150, 151, 152, 153].map { |m| m * DAYS },
         | 
| 14 | 
            -
                  6  => [181, 182, 183, 184].map { |m| m * DAYS },
         | 
| 15 | 
            -
                  7  => [212, 213, 214, 215].map { |m| m * DAYS },
         | 
| 16 | 
            -
                  8  => [242, 243, 244, 245].map { |m| m * DAYS },
         | 
| 17 | 
            -
                  9  => [273, 274, 275, 276].map { |m| m * DAYS },
         | 
| 18 | 
            -
                  10 => [303, 304, 305, 306].map { |m| m * DAYS },
         | 
| 19 | 
            -
                  11 => [334, 335, 336, 337].map { |m| m * DAYS },
         | 
| 20 | 
            -
                  12 => [365, 366]          .map { |m| m * DAYS }
         | 
| 21 | 
            -
                }
         | 
| 22 | 
            -
                YEARS = [365, 366]
         | 
| 23 | 
            -
             | 
| 24 | 
            -
                def next(base, validations)
         | 
| 25 | 
            -
                end
         | 
| 26 | 
            -
             | 
| 27 | 
            -
                def prev(base, validations)
         | 
| 28 | 
            -
                end
         | 
| 29 | 
            -
              end
         | 
| 30 | 
            -
            end
         |