class GbAgencies::Agencies

Constants

LOCAL
NATIONAL
SCOPEPFX
SECTOR

Public Class Methods

new(lang, labels = nil, issuer = nil) click to toggle source
# File lib/gb_agencies/gb_agencies.rb, line 3
def initialize(lang, labels = nil, issuer = nil)
  @lang = lang
  @labels = labels || { "PRC" => "", "industry_standard" => "",
                        "local_standard" => "", "enterprise_standard" => "",
                        "social_standard" => "" }
  @issuer = issuer || "(not supplied)"
end

Public Instance Methods

docidentifier(scope, prefix, mandate, docyear, docnum) click to toggle source
# File lib/gb_agencies/gb_agencies.rb, line 326
def docidentifier(scope, prefix, mandate, docyear, docnum)
  initslash = %r{^/}.match(docnum)
  dn = case scope
       when nil
         docnum
       when "local"
         "#{SCOPEPFX[scope.to_sym]}#{mandate_suffix(prefix, mandate)}/"\
           "#{docnum}".gsub(%r{/([TZ])/}, "/\\1 ")
       when "social-group", "enterprise"
         "#{mandate_suffix(SCOPEPFX[scope.to_sym], mandate)}/"\
           "#{prefix}#{initslash ? "" : " "}#{docnum}"
       else
         "#{mandate_suffix(prefix, mandate)}#{initslash ? "" : " "}#{docnum}"
       end
  dn += "—#{docyear}" if dn && docyear
  dn
end
gb_mandate_suffix(prefix, mandate) click to toggle source
# File lib/gb_agencies/gb_agencies.rb, line 253
def gb_mandate_suffix(prefix, mandate)
  if prefix == "GB"
    prefix += "/T" if mandate == "recommended"
    prefix += "/Z" if mandate == "guide"
  end
  prefix
end
gbtype_validate(scope, prefix) click to toggle source
# File lib/gb_agencies/gb_agencies.rb, line 344
def gbtype_validate(scope, prefix)
  case scope
  when "national"
    NATIONAL.dig(@lang, prefix.to_sym) ||
      warn("GB: #{prefix} is not a recognised national prefix")
  when "sector"
    SECTOR.dig(@lang, prefix.to_sym) ||
      warn("GB: #{prefix} is not a recognised sector prefix")
  when "local"
    LOCAL.dig(@lang, prefix.to_sym) ||
      warn("GB: #{prefix} is not a recognised local prefix")
  end
end
mandate_suffix(prefix, mandate) click to toggle source
# File lib/gb_agencies/gb_agencies.rb, line 261
def mandate_suffix(prefix, mandate)
  prefix += "/T" if mandate == "recommended"
  prefix += "/Z" if mandate == "guide"
  prefix
end
standard_agency(scope, prefix, mandate) click to toggle source

return agency name, allowing arrays in output

# File lib/gb_agencies/gb_agencies.rb, line 305
def standard_agency(scope, prefix, mandate)
  case scope
  when "national"
    NATIONAL&.dig(@lang, gb_mandate_suffix(prefix, mandate).to_sym,
                  :admin) || nil
  when "sector"
    SECTOR&.dig(@lang, prefix.to_sym, :admin) || nil
  when "local"
    "#{LOCAL&.dig(@lang, prefix.to_sym) || 'XXXX'}#{@labels["local_issuer"]}" 
  when "enterprise", "social-group"
    @issuer || nil
  when "professional" then "PROFESSIONAL STANDARD" # TODO
  end
end
standard_agency1(scope, prefix, mandate) click to toggle source

return agency name as single string

# File lib/gb_agencies/gb_agencies.rb, line 287
def standard_agency1(scope, prefix, mandate)
  case scope
  when "national"
    ret = NATIONAL&.dig(@lang, gb_mandate_suffix(prefix, mandate).to_sym,
                        :admin) || nil
    ret = ret.join(" ") if ret && ret.is_a?(Array)
    ret
  when "sector"
    SECTOR&.dig(@lang, prefix.to_sym, :admin) || nil
  when "local"
    LOCAL&.dig(@lang, prefix.to_sym) || nil 
  when "enterprise", "social-group"
    @issuer || nil
  when "professional" then "PROFESSIONAL STANDARD" # TODO
  end
end
standard_class(scope, prefix, mandate) click to toggle source
# File lib/gb_agencies/gb_agencies.rb, line 267
def standard_class(scope, prefix, mandate)
  spc = @lang == "zh" ? "" : " "
  case scope
  when "national"
    NATIONAL&.dig(@lang, gb_mandate_suffix(prefix, mandate).to_sym,
                  :name) || "XXXX"
  when "sector"        
    "#{@labels["PRC"]}#{spc}#{SECTOR&.dig(@lang, prefix.to_sym, 
    :industry) || 'XXXX'}#{spc}#{@labels["industry_standard"]}"
  when "local"
    "#{LOCAL&.dig(@lang, prefix.to_sym) || 'XXXX'}#{spc}#{@labels["local_standard"]}"
    when "enterprise" 
      #issuer = get_metadata[:issuer]
      "#{@issuer}#{spc}#{@labels["enterprise_standard"]}"
    when "social-group" then @labels["social_standard"]
    when "professional" then "PROFESSIONAL STANDARD" # TODO
    end
end