Class: Ddr::Structures::ComponentTypeTerm
- Inherits:
-
Object
- Object
- Ddr::Structures::ComponentTypeTerm
- Defined in:
- lib/ddr/structures/component_type_term.rb
Constant Summary collapse
- CONFIG_FILE =
::File.join(Rails.root, 'config', 'structure_component_type.yml')
- @@lookup =
{}
Class Method Summary collapse
Class Method Details
.load_lookup ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/ddr/structures/component_type_term.rb', line 18 def self.load_lookup config = YAML::load(::File.read(CONFIG_FILE)) config.each do |type_term, media_types| media_types.each do |media_type| lookup_key = Regexp.new("\\A#{media_type.gsub('*', '.*')}\\Z") @@lookup[lookup_key] = type_term end end end |
.lookup_table ⇒ Object
13 14 15 16 |
# File 'lib/ddr/structures/component_type_term.rb', line 13 def self.lookup_table load_lookup if @@lookup.empty? @@lookup end |
.term(media_type) ⇒ Object
8 9 10 11 |
# File 'lib/ddr/structures/component_type_term.rb', line 8 def self.term(media_type) hit = lookup_table.detect { |k,v| media_type =~ k } hit.last if hit end |