class Almicube::Key
Constants
- ALLOWED_OPTIONS
- KEY_PATTERN
Attributes
config[RW]
options[R]
ranking[R]
Public Class Methods
new(ranking, options={})
click to toggle source
# File lib/almicube/key.rb, line 11 def initialize(ranking, options={}) @ranking = ranking @options = select ranking.options.merge(options) @config ||= Config.config end
Public Instance Methods
[](name)
click to toggle source
# File lib/almicube/key.rb, line 22 def [](name) options[name.to_sym] end
[]=(name, value)
click to toggle source
# File lib/almicube/key.rb, line 26 def []=(name, value) options[name.to_sym] = value if self.class::ALLOWED_OPTIONS.include? name.to_sym end
merge!(options={})
click to toggle source
# File lib/almicube/key.rb, line 17 def merge!(options={}) @options = select @options.merge(options) self end
method_missing(m, *args, &block)
click to toggle source
Calls superclass method
# File lib/almicube/key.rb, line 30 def method_missing(m, *args, &block) if to_str.respond_to? m to_str.send(m, *args, &block) else super end end
to_str()
click to toggle source
# File lib/almicube/key.rb, line 38 def to_str key = config.key_format.clone key.match( self.class::KEY_PATTERN ) do |m| value = options.fetch(m[1].to_sym, '') value = value.strftime(options.fetch(:date_format, '%Y%m%d')) if value.is_a? Date value = value.label if value.kind_of? Selector::Base key.gsub! m[0], value.to_s end while key =~ self.class::KEY_PATTERN key end
Protected Instance Methods
select(options={})
click to toggle source
# File lib/almicube/key.rb, line 54 def select(options={}) options.select { |k| self.class::ALLOWED_OPTIONS.include? k.to_sym } end