Class: FieldMapper::Types::List
- Inherits:
-
Object
- Object
- FieldMapper::Types::List
- 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
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(type, values = []) ⇒ List
constructor
A new instance of List.
- #name ⇒ Object
- #plat_list? ⇒ Boolean
- #valid?(list) ⇒ Boolean
Constructor Details
#initialize(type, values = []) ⇒ List
Returns a new instance of List.
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
#type ⇒ Object (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
Instance Method Details
#name ⇒ Object
32 33 34 |
# File 'lib/field_mapper/types/list.rb', line 32 def name self.class.name end |
#plat_list? ⇒ Boolean
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
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 |