Class: ServiceTypeValue

Inherits:
Object
  • Object
show all
Defined in:
app/models/service_type_value.rb

Overview

This model is the actual list of valid service types. Not ActiveRecord, just load from config files into memory (loaded on file load).

ServiceTypeValues have human-displayable names, that are controlled by Rails I18n, using standard Rails I18n pluralization forms, so for instance:

For a ServiceTypeValue with name ‘fulltext’, key in i18n at ‘umlaut.service_type_names.fulltext.one’ represents the singular (non-plural) name of objects of this ServiceTypeValue, and ‘umlaut.service_type_names.fulltext.other’ is the plural name.

Other languages may have more complex pluralization rules, but Umlaut at present only looks up a plural form for 10 items, so ‘other’ is probably all that is used.

Constant Summary collapse

@@distro_conf_file =
File.join(Umlaut::Engine.root, "db", "orig_fixed_data", "service_type_values.yml")
@@local_conf_file =
File.join(Rails.root, "config", "umlaut_service_type_values.yml")

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ ServiceTypeValue

Returns a new instance of ServiceTypeValue.



22
23
24
25
26
# File 'app/models/service_type_value.rb', line 22

def initialize(hash)
  hash.each_pair do |key, value|
    self.send(key.to_s+"=", value)
  end
end

Class Attribute Details

.valuesObject

Returns the value of attribute values.



20
21
22
# File 'app/models/service_type_value.rb', line 20

def values
  @values
end

Instance Attribute Details

#display_nameObject



36
37
38
# File 'app/models/service_type_value.rb', line 36

def display_name
  I18n.t(self.name, :scope => "umlaut.service_type_names", :default => :default, :count => 1)
end

#display_name_plural=(value) ⇒ Object (writeonly)

Sets the attribute display_name_plural

Parameters:

  • value

    the value to set the attribute display_name_plural to.



18
19
20
# File 'app/models/service_type_value.rb', line 18

def display_name_plural=(value)
  @display_name_plural = value
end

#idObject

Returns the value of attribute id.



17
18
19
# File 'app/models/service_type_value.rb', line 17

def id
  @id
end

#nameObject

Returns the value of attribute name.



17
18
19
# File 'app/models/service_type_value.rb', line 17

def name
  @name
end

Class Method Details

.[](name) ⇒ Object



32
33
34
# File 'app/models/service_type_value.rb', line 32

def self.[](name)
  find(name)
end

.find(name) ⇒ Object



28
29
30
31
# File 'app/models/service_type_value.rb', line 28

def self.find(name)
  load_values! if values.nil?
  values[name.to_sym] or raise ArgumentError.new("No ServiceTypeValue found for #{name}")
end

.load_values!Object

Loads from config files, distro and local, into memory.



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'app/models/service_type_value.rb', line 54

def self.load_values!
    # Load in starting set of ServiceTypeValue, merge in local defines. 
    
    service_type_values = YAML.load_file( @@distro_conf_file )
    local_overrides = File.exists?( @@local_conf_file ) ?
          YAML.load_file(@@local_conf_file) :
          nil
    # Merge in the params for each service type with possible
    # existing params.
    if ( local_overrides )
      local_overrides.each do |name, params|
        service_type_values[name] ||= {}          
        service_type_values[name].merge!( params )          
      end
    end
    
    self.values = {}
    service_type_values.each_pair do |name, hash|
      self.values[name.to_sym] = ServiceTypeValue.new(hash.merge(:name => name))                              
    end            
end

Instance Method Details

#display_name_pluralizeObject

Some languages may have multiple plural forms, but Umlaut at present is not sophisticated enough to use em all, we just look up the plural form for 10 items – most Umlaut use of plural form is for either zero or indetermininate number. But it still may need enhancing.



45
46
47
# File 'app/models/service_type_value.rb', line 45

def display_name_pluralize
  I18n.t(self.name, :scope => "umlaut.service_type_names", :default => :default, :count => 10)
end