Skip to content

Commit

Permalink
add classes for elements
Browse files Browse the repository at this point in the history
  • Loading branch information
Damianos Mylonakis committed Mar 5, 2012
1 parent 6575414 commit 3da2690
Show file tree
Hide file tree
Showing 11 changed files with 120 additions and 23,588 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require('./lib/ical');
module.exports = require('./lib');
48 changes: 48 additions & 0 deletions lib/calendar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
var Element = require('./element').Element
, util = require('util')
, Event = require('./event').Event

var DELIM = '\r\n'

function Calendar(data) {
this.prodid = data.prodid
this.version = data.version || '2.0'
this.events = data.events
}

util.inherits(Calendar, Element)

Calendar.prototype.addEvent = function (event) {
this.events.push(event)
}

Calendar.prototype.toICal = function () {
var x = 'BEGIN:VCALENDAR' + DELIM
for (var k in this) {
if (this.hasOwnProperty(k)) {
var prop = this[k]
debugger
if (Array.isArray(prop)) {
for (var i = 0; i < prop.length; i++) {
var p = prop[i]
if (p instanceof Element) {
x += p.toICal()
}
else {
x += k.toUpperCase() + ':' + this[k] + DELIM
}
}
}
if (prop instanceof Element) {
x += prop.toICal()
}
else {
x += k.toUpperCase() + ':' + this[k] + DELIM
}
}
}
x += 'END:VCALENDAR'
return x
}

exports.Calendar = Calendar
11 changes: 11 additions & 0 deletions lib/element.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

function Element() {

}

Element.prototype.toICal = function () {
throw new Error('not supported')
}


exports.Element = Element
50 changes: 50 additions & 0 deletions lib/event.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
BEGIN:VEVENT
DTSTART:20111206T150000Z
DTEND:20111206T180000Z
DTSTAMP:20120217T005926Z
UID:[email protected]
ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=ACCEPTED;CN=danmyl
[email protected];X-NUM-GUESTS=0:mailto:[email protected]
CREATED:20111206T013929Z
DESCRIPTION:
LAST-MODIFIED:20111206T013929Z
LOCATION:
SEQUENCE:1
STATUS:TENTATIVE
SUMMARY:557 με δαμον
TRANSP:OPAQUE
CATEGORIES:http://schemas.google.com/g/2005#event
BEGIN:VALARM
ACTION:DISPLAY
DESCRIPTION:This is an event reminder
TRIGGER:-P0DT0H10M0S
END:VALARM
END:VEVENT
*/

var Element = require('./element').Element
, util = require('util')

var DELIM = '\r\n'

function Event(data) {
this.summary = data.summary
this.location = data.location
this.description = data.description
}

util.inherits(Event, Element)

Event.prototype.toICal = function () {
var x = 'BEGIN:VEVENT' + DELIM
for (var k in this) {
if (this.hasOwnProperty(k)) {
x += k.toUpperCase() + ':' + this[k] + DELIM
}
}
x += 'END:VEVENT' + DELIM
return x
}

exports.Event = Event
3 changes: 0 additions & 3 deletions lib/ical.js

This file was deleted.

5 changes: 5 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
Parser: require('./parser').Parser
, Calendar: require('./calendar').Calendar
, Event: require('./event').Event
}
1 change: 0 additions & 1 deletion lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ Parser.prototype._dispatch = function () {
if (limit == -1) {
return;
}
debugger;
var content = this.buffer.substr(0, limit);
this.buffer = this.buffer.slice(limit + 2, limit + 4);
var contentLines = content.split('\r\n');
Expand Down
Loading

0 comments on commit 3da2690

Please sign in to comment.