Sha256: 77559b647faf378ad0915aa546374a10346900f3f0152154c798d933dd4e40eb

Contents?: true

Size: 1.6 KB

Versions: 6

Compression:

Stored size: 1.6 KB

Contents

module GreenButtonData
  module Parser
    class Entry
      include SAXMachine
      include Utilities

      element :id, as: :entry_id

      def id
        @entry_id ||= @self
      end

      element :link, as: :up, value: :href, with: { rel: 'up' }
      element :link, as: :self, value: :href, with: { rel: 'self' }
      elements :link, as: :related, value: :href, with: { rel: 'related' }

      element :content, class: Content, as: :content

      # Published Date
      element :published

      def published
        @published ||= @updated
      end

      def published=(val)
        @published = parse_datetime val
      end

      # Updated Date
      element :updated

      def updated=(val)
        @updated = parse_datetime val
      end

      # Handle PG&E namespacing
      element :'ns1:id', as: :entry_id
      element :'ns1:link', as: :up, value: :href, with: { rel: 'up' }
      element :'ns1:link', as: :self, value: :href, with: { rel: 'self' }
      elements :'ns1:link', as: :related, value: :href, with: { rel: 'related' }
      element :'ns1:content', class: Content, as: :content
      element :'ns1:published', as: :published
      element :'ns1:updated', as: :updated

      element :'ns2:id', as: :entry_id
      element :'ns2:link', as: :up, value: :href, with: { rel: 'up' }
      element :'ns2:link', as: :self, value: :href, with: { rel: 'self' }
      elements :'ns2:link', as: :related, value: :href, with: { rel: 'related' }
      element :'ns2:content', class: Content, as: :content
      element :'ns2:published', as: :published
      element :'ns2:updated', as: :updated
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
green-button-data-2.0.1 lib/green-button-data/parser/entry.rb
green-button-data-2.0.0 lib/green-button-data/parser/entry.rb
green-button-data-1.0.3 lib/green-button-data/parser/entry.rb
green-button-data-1.0.1 lib/green-button-data/parser/entry.rb
green-button-data-1.0.0 lib/green-button-data/parser/entry.rb
green-button-data-0.7.5 lib/green-button-data/parser/entry.rb