Class: MppReader::Project
- Inherits:
-
Object
- Object
- MppReader::Project
- Defined in:
- lib/mpp_reader/project.rb
Overview
A parsed MS Project file. Tasks and resources are read lazily on first access and memoized.
Instance Attribute Summary collapse
-
#application_name ⇒ Object
readonly
Returns the value of attribute application_name.
-
#file_format ⇒ Object
readonly
Returns the value of attribute file_format.
Instance Method Summary collapse
- #assignments ⇒ Object
- #calendar(unique_id) ⇒ Object
- #calendars ⇒ Object
-
#initialize(cfbf, comp_obj) ⇒ Project
constructor
A new instance of Project.
- #resource(unique_id) ⇒ Object
-
#resources ⇒ Object
Calendars carry the resource->calendar links, so reading them also fills Resource#calendar_unique_id; force that before handing out resources.
- #task(unique_id) ⇒ Object
- #tasks ⇒ Object
Constructor Details
#initialize(cfbf, comp_obj) ⇒ Project
Returns a new instance of Project.
8 9 10 11 12 |
# File 'lib/mpp_reader/project.rb', line 8 def initialize(cfbf, comp_obj) @cfbf = cfbf @file_format = comp_obj.file_format @application_name = comp_obj.application_name end |
Instance Attribute Details
#application_name ⇒ Object (readonly)
Returns the value of attribute application_name.
6 7 8 |
# File 'lib/mpp_reader/project.rb', line 6 def application_name @application_name end |
#file_format ⇒ Object (readonly)
Returns the value of attribute file_format.
6 7 8 |
# File 'lib/mpp_reader/project.rb', line 6 def file_format @file_format end |
Instance Method Details
#assignments ⇒ Object
28 29 30 |
# File 'lib/mpp_reader/project.rb', line 28 def assignments @assignments ||= reader.read_assignments(tasks.map(&:unique_id).to_set) end |
#calendar(unique_id) ⇒ Object
56 |
# File 'lib/mpp_reader/project.rb', line 56 def calendar(unique_id) = calendars.find { |c| c.unique_id == unique_id } |
#calendars ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/mpp_reader/project.rb', line 32 def calendars @calendars ||= begin list = reader.read_calendars # Derived calendars not used by any resource are leftovers MS # Project does not show; prune them (as MPXJ does). Surviving # resource links are mirrored onto the resources, and unnamed # resource calendars inherit the resource name. by_uid = raw_resources.to_h { |r| [r.unique_id, r] } list.reject! do |cal| cal.base_calendar_unique_id && by_uid[cal.resource_unique_id].nil? end list.each do |cal| res = by_uid[cal.resource_unique_id] next if res.nil? res.calendar_unique_id = cal.unique_id cal.name = res.name || "Unnamed Resource" if cal.name.nil? || cal.name.empty? end end end |
#resource(unique_id) ⇒ Object
58 |
# File 'lib/mpp_reader/project.rb', line 58 def resource(unique_id) = resources_by_uid[unique_id] |
#resources ⇒ Object
Calendars carry the resource->calendar links, so reading them also fills Resource#calendar_unique_id; force that before handing out resources.
23 24 25 26 |
# File 'lib/mpp_reader/project.rb', line 23 def resources calendars raw_resources end |
#task(unique_id) ⇒ Object
54 |
# File 'lib/mpp_reader/project.rb', line 54 def task(unique_id) = tasks_by_uid[unique_id] |
#tasks ⇒ Object
14 15 16 17 18 |
# File 'lib/mpp_reader/project.rb', line 14 def tasks @tasks ||= reader.read_tasks.tap do |list| reader.read_relations(list.to_h { |t| [t.unique_id, t] }) end end |