Sha256: c3d06c7dd30b449771bf73794d03b2ea06b8994cdfdf564281644a022fd40ec7
Contents?: true
Size: 1.25 KB
Versions: 2
Compression:
Stored size: 1.25 KB
Contents
# frozen_string_literal: true require_relative 'base' require_relative 'linestring' module ActiveRecordMysqlSpatial module ActiveRecord module MySQL class Multilinestring < Base attr_accessor :items def type :multilinestring end def to_sql return nil if @items.blank? "MultiLineString(#{to_coordinates_sql})" end def to_coordinates_sql items.map { |linestring| "(#{linestring.to_coordinates_sql})" }.join(',') end def ==(other) items.each_with_index do |item, index| return false if item != other.items[index] end true end private def cast_value(value) @raw = value coordinates, create_raw = extract_coordinates(value) @raw = Geometry.from_coordinates(coordinates, type: :multilinestring).as_binary if create_raw @items = coordinates.map do |linestring| Linestring.new.send( :cast_value, { coordinates: linestring } ) end self rescue StandardError => e @error = e.message self end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems