Class: Eac::Listable::List

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

Direct Known Subclasses

IntegerList, StringList

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lists, item, labels) ⇒ List

Returns a new instance of List.



95
96
97
98
99
100
# File 'lib/eac/listable.rb', line 95

def initialize(lists, item, labels)
  @lists = lists
  @item = item
  @values = build_values(labels)
  apply_constants
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



110
111
112
113
# File 'lib/eac/listable.rb', line 110

def method_missing(name, *args, &block)
  list = find_list_by_method(name)
  list ? list : super
end

Instance Attribute Details

#itemObject (readonly)

Returns the value of attribute item.



93
94
95
# File 'lib/eac/listable.rb', line 93

def item
  @item
end

Instance Method Details

#i18n_keyObject



119
120
121
# File 'lib/eac/listable.rb', line 119

def i18n_key
  "eac.listable.#{class_i18n_key}.#{item}"
end

#instance_value(instance) ⇒ Object



123
124
125
126
127
# File 'lib/eac/listable.rb', line 123

def instance_value(instance)
  v = instance.send(item)
  return @values[v] if @values.key?(v)
  raise "List value unkown: #{v} (Source: #{@lists.source}, Item: #{item})"
end

#optionsObject



106
107
108
# File 'lib/eac/listable.rb', line 106

def options
  @values.values.map { |v| [v.label, v.value] }
end

#respond_to?(name, include_all = false) ⇒ Boolean

Returns:

  • (Boolean)


115
116
117
# File 'lib/eac/listable.rb', line 115

def respond_to?(name, include_all = false)
  find_list_by_method(name) || super
end

#valuesObject



102
103
104
# File 'lib/eac/listable.rb', line 102

def values
  @values.values.map(&:value)
end