require 'active_support/time_with_zone' module TracksCli class TracksXmlBuilder def xml_for_description(description) "#{description}" end def xml_for_project_id(project_id) "#{project_id}" end def xml_for_show_from(show_from) show_from.nil? ? "" : "#{Time.at(show_from).xmlschema}" end def xml_for_notes(notes) notes.nil? ? "" : "#{notes}" end def xml_for_taglist(taglist) unless taglist.nil? tags = taglist.split(",") if tags.length > 0 tags = tags.collect { |tag| "#{tag.strip}" unless tag.strip.empty? }.join('') return "#{tags}" end else return "" end end def xml_for_context(context_name, context_id) if context_name && !context_name.empty? return "#{context_name}" else return "#{context_id}" end end def xml_for_predecessor(dependend, predecessor) dependend ? "#{predecessor}" : "" end def build_todo_xml(todo) props = [ xml_for_description(todo[:description]), xml_for_project_id(todo[:project_id]), xml_for_show_from(todo[:show_from]), xml_for_notes(todo[:notes]), xml_for_taglist(todo[:taglist]), xml_for_context(todo[:context_name], todo[:context_id]), xml_for_predecessor(todo[:is_dependend], todo[:predecessor]) ] "#{props.join("")}" end def build_project_xml(project) "#{project[:description]}#{project[:default_context_id]}" end end end