Sha256: 20bf65a0ebf22dbc3882772ada05cb1da4a81fc69d0b876581d0f64e72214c2b

Contents?: true

Size: 1.04 KB

Versions: 2

Compression:

Stored size: 1.04 KB

Contents

require 'json'

module GDAL
  module ColorTableExtensions

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

      0.upto(color_entry_count - 1).map do |i|
        color_entry(i).send("color#{color_number}".to_sym)
      end
    end

    # @return [Array<GDAL::ColorEntry>]
    def color_entries
      0.upto(color_entry_count - 1).map 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
      0.upto(color_entry_count - 1).map do |i|
        color_entry_as_rgb(i)
      end
    end

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

    # @return [String]
    def to_json
      as_json.to_json
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ffi-gdal-1.0.0.beta3 lib/gdal/color_table_extensions.rb
ffi-gdal-1.0.0.beta1 lib/gdal/color_table_extensions.rb