Sha256: 98bc2cd60675b1da94e64770a9b3b187eea6613bf35ec0799e0a756e1b86404b
Contents?: true
Size: 1.26 KB
Versions: 99
Compression:
Stored size: 1.26 KB
Contents
require "csv" require "local_authority" require "safe_html" class LocalService include Mongoid::Document field :description, type: String field :lgsl_code, type: Integer field :providing_tier, type: Array GOVSPEAK_FIELDS = [] validates_presence_of :lgsl_code, :providing_tier validates_uniqueness_of :lgsl_code validates :providing_tier, inclusion: { in: [%w{county unitary}, %w{district unitary}, %w{district unitary county}] } validates_with SafeHtml def self.find_by_lgsl_code(lgsl_code) LocalService.where(lgsl_code: lgsl_code).first end def preferred_interaction(snac_or_snac_list, lgil_override = nil) provider = preferred_provider(snac_or_snac_list) provider && provider.preferred_interaction_for(lgsl_code, lgil_override) end def preferred_provider(snac_or_snac_list) snac_list = [*snac_or_snac_list] providers = LocalAuthority.for_snacs(snac_list) select_tier(providers) end def provided_by LocalAuthority.where("local_interactions.lgsl_code" => lgsl_code) .any_in(tier: providing_tier) end private def select_tier(authorities) by_tier = Hash[authorities.map {|a| [a.tier, a]}] tier = providing_tier.find { |t| by_tier.has_key?(t) } tier && by_tier[tier] end end
Version data entries
99 entries across 99 versions & 1 rubygems