Sha256: 64ba89a26ba34922c65d6a0b28af44f20cf4a3a0119d0d50d2126429961c8129

Contents?: true

Size: 1.02 KB

Versions: 30

Compression:

Stored size: 1.02 KB

Contents

require_relative 'lab_resource'

module Medivo
  class Lab < LabResource
    unless defined? LAB_CORP_ID
      LAB_CORP_ID = 129
      QUEST_ID = 119
      LAB_CORP_NAME = :lab_corp
      QUEST_NAME = :quest
      LAB_ID_TO_NAME = {LAB_CORP_ID => LAB_CORP_NAME, QUEST_ID => QUEST_NAME}
      LAB_ID_TO_SHORT_NAME = {LAB_CORP_ID => 'LC', QUEST_ID => 'QD'}
      LAB_ID_TO_PRETTY_NAME = {LAB_CORP_ID => 'Lab Corp', QUEST_ID => 'Quest Diagnostics'}
    end

    def self.findLabs(zip_code, radius = 15)
      find(:all, :from => "/find_psc/#{zip_code}", :params=>{:radius=>radius}).sort_by(&:distance)
    end

    def self.data_for_zip(zip='')
      zip = zip.to_s.match(/(\d{5})/) ? $1 : nil
      return {} unless zip
      labs = findLabs(zip)
      zip_info = Geocoder.coordinates(zip)
      {:labs => labs, :zip_location => {:title=>zip, :lat=>zip_info[0], :lng=>zip_info[1]}}
    end

    def lab_name
      LAB_ID_TO_PRETTY_NAME[lab_id]
    end

    def as_json(options={})
      attributes.merge(:lab_name => self.lab_name)
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
medivo-0.1.8 app/models/medivo/lab.rb
medivo-0.1.7 app/models/medivo/lab.rb
medivo-0.1.6 app/models/medivo/lab.rb
medivo-0.1.5 app/models/medivo/lab.rb
medivo-0.1.4 app/models/medivo/lab.rb
medivo-0.1.3 app/models/medivo/lab.rb
medivo-0.1.2 app/models/medivo/lab.rb
medivo-0.1.1 app/models/medivo/lab.rb
medivo-0.1.0 app/models/medivo/lab.rb
medivo-0.0.13 app/models/medivo/lab.rb