Class: SuperList::Data
- Inherits:
-
Object
- Object
- SuperList::Data
- Defined in:
- lib/super_list.rb
Overview
Data Store
Instance Method Summary collapse
- #get_key(value, options = {}) ⇒ Object
- #get_value(key, options = {}) ⇒ Object
-
#initialize(values, options) ⇒ Data
constructor
A new instance of Data.
- #keys ⇒ Object
- #map(type = :default, options = {}, &blk) ⇒ Object
- #options ⇒ Object
- #values(type = :default, options = {}) ⇒ Object
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, ) @values, @options = values, end |
Instance Method Details
#get_key(value, options = {}) ⇒ Object
62 63 64 |
# File 'lib/super_list.rb', line 62 def get_key(value,={}) keys[values().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.merge() value = @values[key] value = value.is_a?(Hash) ? value : {:default => value} List.new(value, ) end |
#keys ⇒ Object
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, ={}, &blk) keys.zip(values(type,)).map &blk end |
#options ⇒ Object
66 67 68 |
# File 'lib/super_list.rb', line 66 def @options end |
#values(type = :default, options = {}) ⇒ Object
46 47 48 49 |
# File 'lib/super_list.rb', line 46 def values(type=:default, ={}) , type = type, :default if type.is_a?(Hash) keys.map {|x| get_value(x, ).to_s(type) } end |