Sha256: 670e285d3cfc45aaadcb9aa0f718840822ac9f1df14ed9cc39816115b0756e51

Contents?: true

Size: 807 Bytes

Versions: 5

Compression:

Stored size: 807 Bytes

Contents

module GreenButtonData
  module Parser
    class Interval
      include SAXMachine
      include Utilities

      element :duration, class: Integer do |t|
        normalize_epoch t
      end

      element :start, class: Integer do |t|
        normalize_epoch t
      end

      def starts_at
        Time.at(normalize_epoch(@start)).utc.to_datetime
      end

      def ends_at
        Time.at(normalize_epoch(@start + @duration)).utc.to_datetime
      end

      # Standard ESPI namespacing
      element :'espi:duration', class: Integer, as: :duration
      element :'espi:start', class: Integer, as: :start

      # Special case for PG&E which uses generic namespacing
      element :'ns0:duration', class: Integer, as: :duration
      element :'ns0:start', class: Integer, as: :start
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
green-button-data-0.2.1 lib/green-button-data/parser/interval.rb
green-button-data-0.2.0 lib/green-button-data/parser/interval.rb
green-button-data-0.1.2 lib/green-button-data/parser/interval.rb
green-button-data-0.1.1 lib/green-button-data/parser/interval.rb
green-button-data-0.1.0 lib/green-button-data/parser/interval.rb