Sha256: 1ff09a3e36d76264c5b7c4fc6936b1a57c4974290d8a00317b0bc104ec6873f4

Contents?: true

Size: 1.44 KB

Versions: 3

Compression:

Stored size: 1.44 KB

Contents

# frozen_string_literal: true

require "time"

module OGR
  module InternalHelpers
    def self.included(base)
      base.extend(ClassMethods)
    end

    # @private
    module ClassMethods
      # Makes the interface consistent with the access flags for GDAL.
      #
      # @param flag [String] 'w' for writing, 'r' for reading.
      def _boolean_access_flag(flag)
        case flag
        when "w" then true
        when "r" then false
        else raise "Invalid access_flag '#{flag}'.  Use 'r' or 'w'."
        end
      end

      # OGR's time zone rules:
      #   * 0 = unknown
      #   * 1 = local time
      #   * 100 = GMT
      #
      # This converts the OGR integer into something usable by Ruby's DateTime.
      #
      # @param time_zone [Integer]
      def _format_time_zone_for_ruby(time_zone)
        case time_zone
        when 0 then nil
        when 1 then (Time.now.getlocal.utc_offset / 3600).to_s
        when 100 then "+0"
        else raise "Unable to process time zone: #{time_zone}"
        end
      end

      # OGR's time zone rules:
      #   * 0 = unknown
      #   * 1 = local time
      #   * 100 = GMT
      #
      # This converts Ruby's DateTime time zone info into OGR's integer.
      #
      # @param time_zone [String]
      def _format_time_zone_for_ogr(time_zone)
        if /(00:00|GMT)\z/.match?(time_zone)
          100
        elsif time_zone
          1
        else
          0
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ffi-gdal-1.1.0 lib/ogr/internal_helpers.rb
ffi-gdal-1.0.4 lib/ogr/internal_helpers.rb
ffi-gdal-1.0.3 lib/ogr/internal_helpers.rb