Class: MPXJ::Reader
- Inherits:
-
Object
- Object
- MPXJ::Reader
- Defined in:
- lib/mpxj/reader.rb
Overview
Used to read a project plan from a file
Class Method Summary collapse
- .path_separator ⇒ Object
-
.read(file_name, zone = nil) ⇒ Project
Reads a project plan from a file, and returns a Project instance which provides access to the structure and attributes of the project data.
- .windows? ⇒ Boolean
Class Method Details
.path_separator ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/mpxj/reader.rb', line 35 def self.path_separator if windows? ";" else ":" end end |
.read(file_name, zone = nil) ⇒ Project
Reads a project plan from a file, and returns a Project instance which provides access to the structure and attributes of the project data. Note that an optional timezone can be supplied to ensue that all date-time values returned are in the specified timezone.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/mpxj/reader.rb', line 15 def self.read(file_name, zone = nil) project = nil json_file = Tempfile.new([File.basename(file_name, ".*"), '.json']) tz = zone || Time.zone || ActiveSupport::TimeZone["UTC"] begin classpath = Dir["#{File.dirname(__FILE__)}/*.jar"].join(path_separator) java_output = `java -cp \"#{classpath}\" net.sf.mpxj.sample.MpxjConvert \"#{file_name}\" \"#{json_file.path}\"` if $?.exitstatus != 0 raise "Failed to read file: #{java_output}" end project = Project.new(json_file, tz) ensure json_file.close json_file.unlink end project end |
.windows? ⇒ Boolean
44 45 46 |
# File 'lib/mpxj/reader.rb', line 44 def self.windows? (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil end |