Class: Entity::FormatIndex
- Inherits:
-
Hash
- Object
- Hash
- Entity::FormatIndex
- Defined in:
- lib/scout/entity/format.rb
Instance Method Summary collapse
- #[](value) ⇒ Object
- #[]=(key, value) ⇒ Object
- #find(value) ⇒ Object
- #include?(value) ⇒ Boolean
-
#initialize ⇒ FormatIndex
constructor
A new instance of FormatIndex.
- #orig_include? ⇒ Object
Constructor Details
#initialize ⇒ FormatIndex
Returns a new instance of FormatIndex.
13 14 15 |
# File 'lib/scout/entity/format.rb', line 13 def initialize @find_cache = {} end |
Instance Method Details
#[](value) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/scout/entity/format.rb', line 44 def [](value) res = super return res if res key = find(value) key ? super(key) : nil end |
#[]=(key, value) ⇒ Object
51 52 53 54 |
# File 'lib/scout/entity/format.rb', line 51 def []=(key,value) @find_cache = {} super(key, value) end |
#find(value) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/scout/entity/format.rb', line 17 def find(value) @find_cache ||= {} if @find_cache.include?(value) @find_cache[value] else @find_cache[value] = begin if orig_include? value value else value = value.to_s found = nil each do |k,v| if value == k.to_s found = k break elsif value =~ /\(#{Regexp.quote k.to_s}\)/ found = k break end end found end end end end |
#include?(value) ⇒ Boolean
56 57 58 |
# File 'lib/scout/entity/format.rb', line 56 def include?(value) find(value) != nil end |
#orig_include? ⇒ Object
11 |
# File 'lib/scout/entity/format.rb', line 11 alias orig_include? include? |