Sha256: 2ea92ec3d30a238a6718f02bf0f32165adeb8e4fb7ee4c7f8d9df74c35beba1c

Contents?: true

Size: 498 Bytes

Versions: 3

Compression:

Stored size: 498 Bytes

Contents

require "active_resource"

module Ddr
  class Language < ActiveResource::Base

    self.site = ENV["DDR_AUX_API_URL"]

    def self.call(obj)
      obj.language.map do |lang|
        find_by_code(lang)
      end
    rescue ActiveResource::ResourceNotFound => e
      raise Ddr::NotFoundError, e
    end

    def self.find_by_code(code)
      return unless code
      new get(:find, code: code)
    end

    def self.codes
      all.map(&:code)
    end

    def to_s
      label
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ddr-core-0.3.0 app/models/ddr/language.rb
ddr-core-0.2.2 app/models/ddr/language.rb
ddr-core-0.2.1 app/models/ddr/language.rb