trabajo-afectivo/lib/sequencer/unit/import/freshdesk/time_entry/mapping.rb

45 lines
1.1 KiB
Ruby
Raw Normal View History

2022-01-01 13:38:12 +00:00
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
2021-05-25 12:30:12 +00:00
class Sequencer
class Unit
module Import
module Freshdesk
module TimeEntry
class Mapping < Sequencer::Unit::Base
include ::Sequencer::Unit::Import::Common::Mapping::Mixin::ProvideMapped
uses :resource, :id_map
def process
provide_mapped do
{
time_unit: time_unit,
ticket_id: ticket_id,
created_by_id: agent_id,
created_at: resource['created_at'],
updated_at: resource['updated_at'],
}
end
end
private
def time_unit
hours, minutes = resource['time_spent'].match(%r{(\d{2}):(\d{2})}).captures
(hours.to_i * 60) + minutes.to_i
end
def ticket_id
id_map['Ticket'][resource['ticket_id']]
end
def agent_id
id_map['User'][resource['agent_id']]
end
end
end
end
end
end
end