class Fech::Mapped
Fech::Mapped
is a thin wrapper around Hash which allows values to be referenced either by key or by an alias specified in the associated Filing's Translations.
Attributes
filing[RW]
row_type[RW]
Public Class Methods
new(filing, row_type)
click to toggle source
# File lib/fech/mapped.rb, line 11 def initialize(filing, row_type) @filing = filing @row_type = row_type end
Public Instance Methods
[](key, &block)
click to toggle source
Just calls Hash's [] method, unless the specified key doesn't exist, in which case it checks for any aliases on the filing's translator.
# File lib/fech/mapped.rb, line 19 def [](key, &block) if has_key?(key) old_bracket(key, &block) else # Look up aliases in reverse, to find the most recent one # Does not allow (obvious) recursion aliias = filing.translator.aliases.reverse.detect do |a| a[:alias] == key && a[:row].match(row_type) && a[:alias] != a[:for] end # Pass the key this alias references back to this function aliias ? old_bracket(aliias[:for], &block) : nil end end
Also aliased as: old_bracket
method_missing(method, *args, &block)
click to toggle source
# File lib/fech/mapped.rb, line 33 def method_missing(method, *args, &block) self[method] end