Sha256: bbe67cfb00d9c2ca5e5403e6ab0b31062976701b0f3877d5ffc5a2ec01dd4c37

Contents?: true

Size: 1.53 KB

Versions: 99

Compression:

Stored size: 1.53 KB

Contents

require "csv"
require "local_interaction"
require "safe_html"

class LocalAuthority
  include Mongoid::Document

  embeds_many :local_interactions

  field :name,               type: String
  field :snac,               type: String
  field :local_directgov_id, type: Integer
  field :tier,               type: String
  field :contact_address,    type: Array
  field :contact_url,        type: String
  field :contact_phone,      type: String
  field :contact_email,      type: String

  GOVSPEAK_FIELDS = []

  validates_uniqueness_of :snac
  validates_presence_of   :snac, :local_directgov_id, :name, :tier
  validates_with SafeHtml

  scope :for_snacs, ->(snacs) { any_in(snac: snacs) }

  def self.find_by_snac(snac)
    for_snacs([snac]).first
  end

  def provides_service?(lgsl_code, lgil_code = nil)
    interactions_for(lgsl_code, lgil_code).any?
  end

  def interactions_for(lgsl_code, lgil_code = nil)
    interactions = local_interactions.where(lgsl_code: lgsl_code)
    if lgil_code
      interactions.where(lgil_code: lgil_code)
    else
      interactions
    end
  end

  def preferred_interaction_for(lgsl_code, lgil_code = nil)
    interactions = local_interactions.where(lgsl_code: lgsl_code)
    if lgil_code
      interactions.where(lgil_code: lgil_code).first
    else
      interactions.excludes(
        lgil_code: LocalInteraction::LGIL_CODE_PROVIDING_INFORMATION
      ).order_by([:lgil_code, :asc]).first ||
      interactions.where(
        lgil_code: LocalInteraction::LGIL_CODE_PROVIDING_INFORMATION
      ).first
    end
  end

end

Version data entries

99 entries across 99 versions & 1 rubygems

Version Path
govuk_content_models-28.0.0 app/models/local_authority.rb
govuk_content_models-27.2.0 app/models/local_authority.rb
govuk_content_models-27.1.0 app/models/local_authority.rb
govuk_content_models-27.0.0 app/models/local_authority.rb
govuk_content_models-26.2.0 app/models/local_authority.rb
govuk_content_models-26.1.0 app/models/local_authority.rb
govuk_content_models-26.0.0 app/models/local_authority.rb
govuk_content_models-25.0.0 app/models/local_authority.rb
govuk_content_models-24.2.0 app/models/local_authority.rb
govuk_content_models-24.1.0 app/models/local_authority.rb
govuk_content_models-24.0.1 app/models/local_authority.rb
govuk_content_models-24.0.0 app/models/local_authority.rb
govuk_content_models-23.0.0 app/models/local_authority.rb
govuk_content_models-22.2.0 app/models/local_authority.rb
govuk_content_models-22.1.2 app/models/local_authority.rb
govuk_content_models-22.1.1 app/models/local_authority.rb
govuk_content_models-22.1.0 app/models/local_authority.rb
govuk_content_models-22.0.0 app/models/local_authority.rb
govuk_content_models-21.0.0 app/models/local_authority.rb
govuk_content_models-20.2.0 app/models/local_authority.rb