riboseinc / ruby-vobject

Ruby library for parsing vObjects
BSD 2-Clause "Simplified" License
10 stars 3 forks source link

New Vobject::Property and Vobject::Component classes to be defined #3

Closed PeterTKY closed 7 years ago

PeterTKY commented 7 years ago

class Vobject::Property

Vobject::Component

PeterTKY commented 7 years ago

Have defined the two new classes. Some new specs required...

ronaldtse commented 7 years ago

Parsing should output an object hierarchy instead of a hash:

Now:

{:VCALENDAR=>{:VERSION=>{:value=>"2.0"},...}

Should be:

Vobject::Component::Vcalendar(:properties => Vobject::Property::Version ...)
opoudjis commented 7 years ago

For my sanity, I think I'm going to keep the parse generating a hash, and convert that hash into an object in postprocessing.

opoudjis commented 7 years ago

I've addressed this, but let me confirm that you like the solution.

Some properties have multiple values, and each value can have its own set of parameters.

For that reason, the Vobject:Property value can be either, for a single value:

or, for multiple values:

Example instance of a parsed object:

#<Vobject::Component:0x007fc0921cfe08
 @children=
  [#<Vobject::Property:0x007fc0921cf908
    @group=nil,
    @params=nil,
    @prop_name=:VERSION,
    @value="2.0">,
   #<Vobject::Property:0x007fc0921cf4a8
    @group=nil,
    @params=nil,
    @prop_name=:PRODID,
    @value="a">,
   #<Vobject::Property:0x007fc0921cf020
    @multiple=
     [#<Vobject::Property:0x007fc0921cef58
       @group=nil,
       @params={:ALTID=>"3"},
       @prop_name=:KIND,
       @value="individual">,
      #<Vobject::Property:0x007fc0921cee90
       @group=nil,
       @params={:ALTID=>"3"},
       @prop_name=:KIND,
       @value="group">,
      #<Vobject::Property:0x007fc0921cee18
       @group=nil,
       @params={:ALTID=>"3"},
       @prop_name=:KIND,
       @value="nec">],
    @prop_name=:KIND>,
   #<Vobject::Component:0x007fc0921cea58
    @children=
     [#<Vobject::Property:0x007fc0921ce7b0
       @group=nil,
       @params=nil,
       @prop_name=:DTSTAMP,
       @value=1998-01-30 13:45:00 UTC>,
      #<Vobject::Property:0x007fc0921ce4b8
       @group=nil,
       @params=nil,
       @prop_name=:UID,
       @value="uid4@example.com">,
      #<Vobject::Property:0x007fc0921ce1c0
       @group=nil,
       @params=nil,
       @prop_name=:GEO,
       @value={:lat=>1.0, :long=>2.0}>,
      #<Vobject::Property:0x007fc0921cdea0
       @group=nil,
       @params=nil,
       @prop_name=:PERCENT_COMPLETE,
       @value=1>,
      #<Vobject::Property:0x007fc0921cdbd0
       @group=nil,
       @params=nil,
       @prop_name=:ORGANIZER,
       @value="mailto:unclesam@example.com">,
      #<Vobject::Property:0x007fc0921cd838
       @multiple=
        [#<Vobject::Property:0x007fc0921cd7e8
          @group=nil,
          @params={:ALTREP=>"ACCEPTED"},
          @prop_name=:ATTENDEE,
          @value="mailto:jqpublic@example.com">,
         #<Vobject::Property:0x007fc0921cd770
          @group=nil,
          @params=
           {:DELEGATED_TO=>
             ["mailto:jqpublic@example.com", "mailto:jdoe@example.com"]},
          @prop_name=:ATTENDEE,
          @value="mailto:jsmith@example.com">],
       @prop_name=:ATTENDEE>,
      #<Vobject::Property:0x007fc0921cd478
       @group=nil,
       @params=nil,
       @prop_name=:DUE,
       @value=1998-04-15 00:00:00 +1000>,
      #<Vobject::Property:0x007fc0921cd1a8
       @group=nil,
       @params=nil,
       @prop_name=:STATUS,
       @value="NEEDS-ACTION">,
      #<Vobject::Property:0x007fc0921cced8
       @group=nil,
       @params=nil,
       @prop_name=:SUMMARY,
       @value="Submit Income Taxes">],
    @comp_name=:VTODO>,
   #<Vobject::Component:0x007fc0921ccbe0
    @children=
     [#<Vobject::Property:0x007fc0921cc960
       @group=nil,
       @params=nil,
       @prop_name=:ACTION,
       @value="AUDIO">,
      #<Vobject::Property:0x007fc0921cc668
       @group=nil,
       @params=nil,
       @prop_name=:TRIGGER,
       @value=1998-04-03 12:00:00 UTC>,
      #<Vobject::Property:0x007fc0921cc370
       @group=nil,
       @params={:FMTTYPE=>"audio/basic"},
       @prop_name=:ATTACH,
       @value="http://example.com/pub/audio-files/ssbanner.aud">,
      #<Vobject::Property:0x007fc0921cc0a0
       @group=nil,
       @params=nil,
       @prop_name=:REPEAT,
       @value=4>,
      #<Vobject::Property:0x007fc0921c7e60
       @group=nil,
       @params=nil,
       @prop_name=:DURATION,
       @value="PT1H">],
    @comp_name=:VALARM>],
 @comp_name=:VCALENDAR>

Please let me know if this is acceptable.

opoudjis commented 7 years ago

And do you want params to be a distinct class instead of a hash?

opoudjis commented 7 years ago

Parameters made distinct class