Sha256: ea083c95e2c0937ccf033999abe97e238aebcc718ca771811a61895dfe60b7aa

Contents?: true

Size: 1.2 KB

Versions: 6

Compression:

Stored size: 1.2 KB

Contents

class Location < ApplicationRecord
  MIN_LATITUDE = -90
  MAX_LATITUDE = 90
  MIN_LONGITUDE = -180
  MAX_LONGITUDE = 180
  FIRST_QUADRANT = :first
  SECOND_QUADRANT = :second
  THIRD_QUADRANT = :third
  FOURTH_QUADRANT = :fourth
  ORIGIN = :origin
  X_AXIS = :x_axis
  Y_AXIS = :y_axis

  has_many :labels, class_name: 'LocationLabel'
  validates :latitude, numericality: { greater_than_or_equal_to: MIN_LATITUDE,
                                       less_than_or_equal_to: MAX_LATITUDE }
  validates :longitude, numericality: { greater_than_or_equal_to: MIN_LONGITUDE,
                                        less_than_or_equal_to: MAX_LONGITUDE }

  # @return [Integer]
  def quadrant # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
    if latitude.positive? && longitude.positive?
      FIRST_QUADRANT
    elsif latitude.positive? && longitude.negative?
      SECOND_QUADRANT
    elsif latitude.negative? && longitude.negative?
      THIRD_QUADRANT
    elsif latitude.negative? && longitude.positive?
      FOURTH_QUADRANT
    elsif latitude.zero? && longitude.zero?
      ORIGIN
    elsif latitude.zero?
      X_AXIS
    else
      Y_AXIS
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
infinum_json_api_setup-0.0.8 spec/dummy/app/models/location.rb
infinum_json_api_setup-0.0.7 spec/dummy/app/models/location.rb
infinum_json_api_setup-0.0.6 spec/dummy/app/models/location.rb
infinum_json_api_setup-0.0.5 spec/dummy/app/models/location.rb
infinum_json_api_setup-0.0.4 spec/dummy/app/models/location.rb
infinum_json_api_setup-0.0.3 spec/dummy/app/models/location.rb