Sha256: be33287d35bc5b7e27f0d03dcde8c4b38f6773cb3b41cffe84465906e951bbe9

Contents?: true

Size: 1.14 KB

Versions: 8

Compression:

Stored size: 1.14 KB

Contents

require 'tempfile'

module MPXJ
  # Used to read a project plan from a file
  class Reader
    # Reads a project plan from a file, and returns a Project instance
    #   which provides access to the structure and attributes of the project data.
    #
    # @param file_name [String] the name of the file to read
    # @return [Project] new Project instance
    def self.read(file_name)
      project = nil
      json_file = Tempfile.new([File.basename(file_name, ".*"), '.json'])
      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)
      ensure
        json_file.close
        json_file.unlink
      end
      project
    end

    # @private
    def self.path_separator
      if windows?
        ";"
      else
        ":"
      end
    end

    # @private
    def self.windows?
      (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
mpxj-5.1.4 lib/mpxj/reader.rb
mpxj-5.1.3 lib/mpxj/reader.rb
mpxj-5.1.2 lib/mpxj/reader.rb
mpxj-5.1.1 lib/mpxj/reader.rb
mpxj-5.1.0 lib/mpxj/reader.rb
mpxj-5.0.0 lib/mpxj/reader.rb
mpxj-4.7.6 lib/mpxj/reader.rb
mpxj-0.5.0 lib/mpxj/reader.rb