Sha256: eca0428b4695d2ec62b0c6e6cbd2c7cbfc04b2fb9f041c369e0d431ede84d839

Contents?: true

Size: 694 Bytes

Versions: 8

Compression:

Stored size: 694 Bytes

Contents

require "ostruct"
require_relative "collection"
require_relative "distance"

module RateCenter
  class RateCenter < OpenStruct
    extend Collection

    class << self
      private

      def data
        ::RateCenter.data_loader.rate_centers
      end

      def load_collection
        data.map do |data|
          rate_center = new(**data)
          closest_city = data["closest_city"]
          next rate_center if closest_city.nil?

          distance_km = closest_city.fetch("distance_km")
          rate_center.closest_city = Distance.new(
            name: closest_city.fetch("name"),
            distance_km:
          )

          rate_center
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
rate_center-0.3.1 lib/rate_center/rate_center.rb
rate_center-0.3.0 lib/rate_center/rate_center.rb
rate_center-0.2.0 lib/rate_center/rate_center.rb
rate_center-0.1.7 lib/rate_center/rate_center.rb
rate_center-0.1.6 lib/rate_center/rate_center.rb
rate_center-0.1.5 lib/rate_center/rate_center.rb
rate_center-0.1.4 lib/rate_center/rate_center.rb
rate_center-0.1.3 lib/rate_center/rate_center.rb