Module: IceT::Conversions::Schedule::ClassMethods

Defined in:
lib/ice_t/conversions.rb

Instance Method Summary collapse

Instance Method Details

#from_json(json_string) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
# File 'lib/ice_t/conversions.rb', line 79

def from_json(json_string)
  return unless json_string
  data = ActiveSupport::JSON.decode(json_string).symbolize_keys
  schedule = self.new(start_time: data[:start_time].to_time, end_time: data[:end_time].to_time)
  data[:rules]["rules"].each{ |rule|
    schedule.add_rule(
      IceT::Rule::Base.from_json(rule.to_json)
    )
  }        
  schedule
end

#from_yaml(yaml_string) ⇒ Object



75
76
77
# File 'lib/ice_t/conversions.rb', line 75

def from_yaml(yaml_string)
  YAML::load(yaml_string)
end