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.
24 25 26 |
# File 'lib/facebook_ads/field_types/list.rb', line 24 def initialize(sub_type) @sub_type = self.class.for(sub_type) end |
Instance Method Details
#deserialize(value, session = nil) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/facebook_ads/field_types/list.rb', line 28 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
52 53 54 |
# File 'lib/facebook_ads/field_types/list.rb', line 52 def serialize(value) JSON.generate(value) end |