Class: SuperList::Data

Inherits:
Object
  • Object
show all
Defined in:
lib/super_list.rb

Overview

Data Store

Instance Method Summary collapse

Constructor Details

#initialize(values, options) ⇒ Data

Returns a new instance of Data.



38
39
40
# File 'lib/super_list.rb', line 38

def initialize(values, options)
  @values, @options = values, options
end

Instance Method Details

#get_key(value, options = {}) ⇒ Object



62
63
64
# File 'lib/super_list.rb', line 62

def get_key(value,options={})
  keys[values(options).index(value)] rescue nil
end

#get_value(key, options = {}) ⇒ Object



55
56
57
58
59
60
# File 'lib/super_list.rb', line 55

def get_value(key,options={})
  options = @options.merge(options)
  value = @values[key]
  value = value.is_a?(Hash) ? value : {:default => value}
  List.new(value, options)
end

#keysObject



42
43
44
# File 'lib/super_list.rb', line 42

def keys
  @values.keys
end

#map(type = :default, options = {}, &blk) ⇒ Object



51
52
53
# File 'lib/super_list.rb', line 51

def map(type=:default, options={}, &blk)
  keys.zip(values(type,options)).map &blk
end

#optionsObject



66
67
68
# File 'lib/super_list.rb', line 66

def options
  @options
end

#values(type = :default, options = {}) ⇒ Object



46
47
48
49
# File 'lib/super_list.rb', line 46

def values(type=:default, options={})
  options, type = type, :default if type.is_a?(Hash)
  keys.map {|x| get_value(x, options).to_s(type) }
end