Class: IceCube::HashInput
- Inherits:
-
Object
- Object
- IceCube::HashInput
- Defined in:
- lib/ice_cube/hash_input.rb
Defined Under Namespace
Classes: Mash
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#initialize(hash) ⇒ HashInput
constructor
A new instance of HashInput.
- #interval ⇒ Object
- #limit_count ⇒ Object
- #limit_time ⇒ Object
- #rule_class ⇒ Object
- #to_rule ⇒ Object
- #validations ⇒ Object
- #week_start ⇒ Object
Constructor Details
Instance Method Details
#[](key) ⇒ Object
26 27 28 |
# File 'lib/ice_cube/hash_input.rb', line 26 def [](key) @input[key] end |
#interval ⇒ Object
46 47 48 |
# File 'lib/ice_cube/hash_input.rb', line 46 def interval @input[:interval] || 1 end |
#limit_count ⇒ Object
58 59 60 |
# File 'lib/ice_cube/hash_input.rb', line 58 def limit_count @input[:count] end |
#limit_time ⇒ Object
54 55 56 |
# File 'lib/ice_cube/hash_input.rb', line 54 def limit_time @limit_time ||= TimeUtil.deserialize_time(@input[:until]) end |
#rule_class ⇒ Object
40 41 42 43 44 |
# File 'lib/ice_cube/hash_input.rb', line 40 def rule_class return @rule_class if @rule_class match = @input[:rule_type].match(/::(\w+Rule)$/) @rule_class = IceCube.const_get(match[1]) if match end |
#to_rule ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/ice_cube/hash_input.rb', line 30 def to_rule return nil unless rule_class rule = rule_class.new(interval, week_start) rule.until(limit_time) if limit_time rule.count(limit_count) if limit_count validations.each do |validation, args| rule.send(validation, *args) end end |
#validations ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/ice_cube/hash_input.rb', line 62 def validations input_validations = Mash.new(@input[:validations] || {}) ValidatedRule::VALIDATION_ORDER.each_with_object({}) do |key, output_validations| args = input_validations[key] output_validations[key] = Array(args) if args end end |
#week_start ⇒ Object
50 51 52 |
# File 'lib/ice_cube/hash_input.rb', line 50 def week_start @input[:week_start] || :sunday end |