Class: Todoist::Util::ParseHelper
- Inherits:
-
Object
- Object
- Todoist::Util::ParseHelper
- Defined in:
- lib/todoist/util/parse_helper.rb
Class Method Summary collapse
- .filter_today(item, key) ⇒ Object
- .format_time(datetime) ⇒ Object
- .make_object(object_as_hash) ⇒ Object
- .make_objects_as_array(object_datas, key = "id") ⇒ Object
- .make_objects_as_hash(object_datas, key = "id") ⇒ Object
- .parse_todoist_date(item, key) ⇒ Object
- .utc_offset_hours ⇒ Object
Class Method Details
.filter_today(item, key) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/todoist/util/parse_helper.rb', line 21 def self.filter_today(item, key) now = DateTime.now if parse_todoist_date(item, key) && parse_todoist_date(item, key) <= DateTime.new(now.year, now.month, now.day, -utc_offset_hours) + 1 return true else return false end end |
.format_time(datetime) ⇒ Object
31 32 33 |
# File 'lib/todoist/util/parse_helper.rb', line 31 def self.format_time(datetime) datetime.strftime("%Y-%m-%dT%H:%M") end |
.make_object(object_as_hash) ⇒ Object
73 74 75 76 77 |
# File 'lib/todoist/util/parse_helper.rb', line 73 def self.make_object(object_as_hash) json = object_as_hash.to_json object = JSON.parse(json, object_class: OpenStruct) return object end |
.make_objects_as_array(object_datas, key = "id") ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/todoist/util/parse_helper.rb', line 35 def self.make_objects_as_array(object_datas, key = "id") objects_as_array = [] object_datas.each do |object_data| begin object = make_object(object_data) 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_as_array << object end end end return objects_as_array end |
.make_objects_as_hash(object_datas, key = "id") ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/todoist/util/parse_helper.rb', line 54 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 |
.parse_todoist_date(item, key) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/todoist/util/parse_helper.rb', line 11 def self.parse_todoist_date(item, key) if item[key] time = Time.parse(item[key]) return time.to_datetime else return nil end end |
.utc_offset_hours ⇒ Object
7 8 9 |
# File 'lib/todoist/util/parse_helper.rb', line 7 def self.utc_offset_hours return Time.now.utc_offset/60/60 end |