lib/todoist/util/parse_helper.rb in todoist-ruby-0.1.1 vs lib/todoist/util/parse_helper.rb in todoist-ruby-0.1.2
- old
+ new
@@ -30,26 +30,45 @@
def self.formatTime(datetime)
datetime.strftime("%Y-%m-%dT%H:%M")
end
- def self.make_objects_as_array(objects_as_hashes, key = "id")
- objects = {}
+ def self.make_objects_as_array(object_datas, key = "id")
+ objects_as_array = []
- objects_as_hashes.each do |object_data|
+ object_datas.each do |object_data|
begin
object = make_object(object_data)
- objects[object.send(key)] = object
+ objects_as_array << object
rescue
# Occasionally the API returns arrays of arrays of hashes
if object_data.kind_of? Array
object = make_object(object_data[1])
- objects[object.send(key)] = object
+ objects_as_array << object
end
end
end
- return objects
+ return objects_as_array
+ end
+
+ def self.make_objects_as_hash(object_datas, key = "id")
+ objects_as_hash = {}
+
+ object_datas.each do |object_data|
+ begin
+ object = make_object(object_data)
+ objects_as_hash[object.send(key)] = object
+ rescue
+ # Occasionally the API returns arrays of arrays of hashes
+ if object_data.kind_of? Array
+
+ object = make_object(object_data[1])
+ objects_as_hash[object.send(key)] = object
+ end
+ end
+ end
+ return objects_as_hash
end
def self.make_object(object_as_hash)
json = object_as_hash.to_json
object = JSON.parse(json, object_class: OpenStruct)