class SuperList::Data

Data Store

Public Class Methods

new(values, options) click to toggle source
# File lib/super_list.rb, line 27
def initialize(values, options)
  @values, @options = values, options
end

Public Instance Methods

get_key(value, opts={}) click to toggle source
# File lib/super_list.rb, line 51
def get_key(value, opts={})
  keys[values(opts).index(value)] rescue nil
end
get_value(key, format=nil, opts={}) click to toggle source
# File lib/super_list.rb, line 40
def get_value(key, format=nil, opts={})
  opts = options.merge(opts)

  value = @values[key]
  format = format || opts[:format] || :default
  result = value.is_a?(Hash) ? value[format] : value

  return I18n.t(result, :scope => opts[:i18n_scope], :default => opts[:i18n_default], :locale => opts[:locale]) if opts[:use_i18n]
  result
end
keys() click to toggle source
# File lib/super_list.rb, line 31
def keys
  @values.keys
end
map(format=nil, opts={}, &blk) click to toggle source
# File lib/super_list.rb, line 55
def map(format=nil, opts={}, &blk)
  if block_given?
    keys.zip(values(format, opts)).map &blk
  else
    keys.zip(values(format, opts))
  end
end
options() click to toggle source
# File lib/super_list.rb, line 71
def options
  SuperList.options.merge(@options)
end
select_options(format=nil, opts={}, &blk) click to toggle source
# File lib/super_list.rb, line 63
def select_options(format=nil, opts={}, &blk)
  if block_given?
    values(format, opts).zip(keys).map &blk
  else
    values(format, opts).zip(keys)
  end
end
values(format=nil, opts={}) click to toggle source
# File lib/super_list.rb, line 35
def values(format=nil, opts={})
  opts, format = format, nil if format.is_a?(Hash)
  keys.map {|key| get_value(key, format, opts) }
end