Module: RecurringSelect

Defined in:
lib/recurring_select.rb,
lib/recurring_select/engine.rb,
lib/recurring_select/version.rb

Defined Under Namespace

Classes: Engine

Constant Summary collapse

VERSION =
"1.3.0"

Class Method Summary collapse

Class Method Details

.dirty_hash_to_rule(params) ⇒ Object


6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/recurring_select.rb', line 6

def self.dirty_hash_to_rule(params)
  if params.is_a? IceCube::Rule
    params
  else
    if params.is_a?(String)
      params = JSON.parse(params)
    end

    params = params.symbolize_keys
    rules_hash = filter_params(params)

    IceCube::Rule.from_hash(rules_hash)
  end
end

.is_valid_rule?(possible_rule) ⇒ Boolean

Returns:

  • (Boolean)

21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/recurring_select.rb', line 21

def self.is_valid_rule?(possible_rule)
  return true if possible_rule.is_a?(IceCube::Rule)
  return false if possible_rule.blank?

  if possible_rule.is_a?(String)
    begin
      JSON.parse(possible_rule)
      return true
    rescue JSON::ParserError
      return false
    end
  end

  # TODO: this should really have an extra step where it tries to perform the final parsing
  return true if possible_rule.is_a?(Hash)

  false #only a hash or a string of a hash can be valid
end