Search code examples
javascriptruby-on-railsyamlrecurring-events

Trouble generating YAML for ice_cube from Javascript


I want to generate recurring events for use with the ice_cube gem from javascript. I'm trying to use http://sourceforge.net/projects/yaml-javascript/ to dump a javascript object to yaml. I'm not quite getting the results I want though. I'm not sure if this is because of a flaw in the library or because I'm doing something wrong.

Here's my code:

<script src='yaml_dumper.js'> </script>
<script>
  yaml_object = new YAML();
  console.log(yaml_object.dump([{
    ':rule_type':'IceCube::YearlyRule',
    ':interval':1,
    ':until':'',
    ':count':'',
    ':validations':{
      ':month_of_year':[6],
      ':day_of_week':{
        '0':[3]}
    }
  }]))
</script>

Here's what I want:

---
:rule_type: IceCube::YearlyRule
:interval: 1
:until:
:count:
:validations:
  :month_of_year:
  - 6
  :day_of_week:
    0:
    - 3

Here's what I'm getting:

--- #YAML:1.0
':count': ''
':interval': 1
':rule_type': IceCube::YearlyRule
':until': ''
':validations':
  ':day_of_week':
  ':month_of_year':
    - 6

The day_of_week parm in particular is missing. Any suggestions?


Solution

  • Seems like it was an issue with the lib. I switched to using this YAML dumper: https://github.com/ingydotnet/yaml-oscon2009-talk/blob/e54dd6a1650c3e80e784f3ada8f59c1b7157fb94/Sample/YAML.js like so: console.log(YAML.dump(obj)) and got the results I was looking for.