Sha256: 25dff00f9b44414a011aa9b4aa458b4dec5ccc90b7280dd134794e47fc8fd412

Contents?: true

Size: 1.37 KB

Versions: 1

Compression:

Stored size: 1.37 KB

Contents

module LotusNotesCalendar
  class Event
  
    attr_accessor :id, :at, :text, :calendar
  
  
    def self.from_xml(calendar, xml_node)
      # xml_node is 'viewentry' node
      
      e = Event.new
      e.id = xml_node['unid']
      e.calendar = calendar
      date_str = xml_node.xpath('entrydata[@name="$6"]/text')[0].content
      e.at = Date.strptime date_str, '%m/%d/%Y'
      e.text = xml_node.xpath('entrydata[@name="$7"]/text')[0].content
      
      return e
      
    end
    
    def self.from_html(calendar, id, html)
      
      e = Event.new
      e.id = id
      e.calendar = calendar
      next_attr = nil
      
      html.xpath('//html/body/form/table/tr/td/font').each do |el|
        
        if next_attr.nil?
          case el.content
          when "Date"
            next_attr = :at
          when "Description"
            next_attr = :text
          end
        else
          case next_attr
          when :at
            e.at = Date.strptime el.content, '%m/%d/%Y'
          when :text
            e.text = el.content
          end
          next_attr = nil
        end
        
      end

      # e.id = xml_node['unid']
      # date_str = xml_node.xpath('entrydata[@name="$6"]/text')[0].content
      # e.at = Date.strptime date_str, '%m/%d/%Y'
      # e.text = xml_node.xpath('entrydata[@name="$7"]/text')[0].content
      
      return e
      
    end
  
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lotus_notes_calendar-0.0.1.pre lib/lotus_notes_calendar/event.rb