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
39 40 41 42 43 44 |
# File 'lib/scout/entity/format.rb', line 39 def [](value) res = super return res if res key = find(value) key ? super(key) : nil end |
#[]=(key, value) ⇒ Object
46 47 48 49 |
# File 'lib/scout/entity/format.rb', line 46 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 |
# File 'lib/scout/entity/format.rb', line 17 def find(value) @find_cache ||= {} @find_cache[value] ||= begin if orig_include? value @find_cache[value] = value else found = nil each do |k,v| if value.to_s == k.to_s found = k break elsif value.to_s =~ /\(#{Regexp.quote k}\)/ found = k break end end found end end end |
#include?(value) ⇒ Boolean
51 52 53 |
# File 'lib/scout/entity/format.rb', line 51 def include?(value) find(value) != nil end |
#orig_include? ⇒ Object
11 |
# File 'lib/scout/entity/format.rb', line 11 alias orig_include? include? |