Class: FieldMapper::Types::List

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/field_mapper/types/list.rb

Constant Summary collapse

ALLOWED_TYPES =
[
  String,
  Integer,
  Float,
  FieldMapper::Standard::Plat
]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, values = []) ⇒ List

Returns a new instance of List.

Raises:



27
28
29
30
# File 'lib/field_mapper/types/list.rb', line 27

def initialize(type, values=[])
  raise InvalidListType.new("#{type} is not a supported list type") unless valid_type?(type)
  @type = type
end

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type.



17
18
19
# File 'lib/field_mapper/types/list.rb', line 17

def type
  @type
end

Class Method Details

.[](type) ⇒ Object



21
22
23
# File 'lib/field_mapper/types/list.rb', line 21

def [](type)
  List.new(type)
end

Instance Method Details

#nameObject



32
33
34
# File 'lib/field_mapper/types/list.rb', line 32

def name
  self.class.name
end

#plat_list?Boolean

Returns:



36
37
38
# File 'lib/field_mapper/types/list.rb', line 36

def plat_list?
  type.ancestors.include?(FieldMapper::Standard::Plat)
end

#valid?(list) ⇒ Boolean

Returns:



40
41
42
43
44
45
# File 'lib/field_mapper/types/list.rb', line 40

def valid?(list)
  return true if list.empty?
  types = list.map{ |v| v.class }.uniq
  return false if types.length > 1
  types.first.ancestors.include? type
end