Class: FacebookAds::FieldTypes::List
- Defined in:
- lib/facebook_ads/field_types/list.rb
Instance Method Summary collapse
- #deserialize(value, session = nil) ⇒ Object
-
#initialize(sub_type) ⇒ List
constructor
A new instance of List.
- #serialize(value) ⇒ Object
Methods included from FacebookAds::FieldTypes
Constructor Details
#initialize(sub_type) ⇒ List
Returns a new instance of List.
12 13 14 |
# File 'lib/facebook_ads/field_types/list.rb', line 12 def initialize(sub_type) @sub_type = self.class.for(sub_type) end |
Instance Method Details
#deserialize(value, session = nil) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/facebook_ads/field_types/list.rb', line 16 def deserialize(value, session = nil) case value when String JSON.parse(value).map { |v| @sub_type.deserialize(v, session) } when Array value.map { |v| @sub_type.deserialize(v, session) } when Hash # Special handle for images if value.length == 1 && value.keys.first == 'images' value = value['images'] end value.map { |_,v| @sub_type.deserialize(v, session) } else [value] end end |
#serialize(value) ⇒ Object
40 41 42 |
# File 'lib/facebook_ads/field_types/list.rb', line 40 def serialize(value) JSON.generate(value) end |