Sha256: 1ea534a24df3a232726e9f0f71ed309edc5dc1007649d45f4676869dea4a6d1c

Contents?: true

Size: 1.16 KB

Versions: 1

Compression:

Stored size: 1.16 KB

Contents

require 'json'

module GDAL
  module ColorTableMixins
    module Extensions
      def color_entries_for(color_number)
        unless (1..4).to_a.include? color_number
          raise "Invalid ColorEntry number 'color#{color_number}'"
        end

        Array.new(color_entry_count) do |i|
          color_entry(i).send("color#{color_number}".to_sym)
        end
      end

      # @return [Array<GDAL::ColorEntry>]
      def color_entries
        Array.new(color_entry_count) do |i|
          color_entry(i)
        end
      end

      # Does the same as #color_entries, but calls #color_entry_as_rgb() instead
      # of #color_entry().
      #
      # @return [Array<GDAL::ColorEntry>]
      def color_entries_as_rgb
        Array.new(color_entry_count) do |i|
          color_entry_as_rgb(i)
        end
      end

      # @return [Hash]
      def as_json(_options = nil)
        {
          color_entry_count: color_entry_count,
          color_entries: color_entries.map(&:as_json),
          palette_interpretation: palette_interpretation
        }
      end

      # @return [String]
      def to_json(options = nil)
        as_json(options).to_json
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ffi-gdal-1.0.0.beta6 lib/gdal/color_table_mixins/extensions.rb