Class: Sal::Version
- Inherits:
-
Object
- Object
- Sal::Version
- Defined in:
- lib/sal/version.rb
Overview
The version class includes the infos to the sal version and the correspondenting file version. The class analyzes with the code the versions. The file version could be changed.
Instance Attribute Summary collapse
-
#file ⇒ Object
Returns the value of attribute file.
-
#td ⇒ Object
Returns the value of attribute td.
Class Method Summary collapse
-
.file_to_td(file_version) ⇒ Object
Change the file version in the correspondenting sal version.
-
.from_code(code) ⇒ Object
Get the version from the code and returns a version object (fabric-method).
-
.from_file(file) ⇒ Object
Get the version from a file and returns a version object (fabric-method).
-
.td_to_file(td_version) ⇒ Object
Convert the sal version in the correspondenting file version.
Instance Method Summary collapse
-
#initialize(version) ⇒ Version
constructor
The version could be initialized with the fileversion or the sal version.
-
#to_code(code) ⇒ Object
Set the file version in the code to the file version of this object.
-
#to_file(filename) ⇒ Object
Set the fileversion of the file.
Constructor Details
#initialize(version) ⇒ Version
The version could be initialized with the fileversion or the sal version. The dot in the version is checked to use the right version type.
12 13 14 15 16 17 18 19 20 |
# File 'lib/sal/version.rb', line 12 def initialize(version) if(version.to_s.include? ".") @td = version @file = Version.td_to_file @td else @file = version @td = Version.file_to_td @file end end |
Instance Attribute Details
#file ⇒ Object
Returns the value of attribute file.
22 23 24 |
# File 'lib/sal/version.rb', line 22 def file @file end |
#td ⇒ Object
Returns the value of attribute td.
22 23 24 |
# File 'lib/sal/version.rb', line 22 def td @td end |
Class Method Details
.file_to_td(file_version) ⇒ Object
Change the file version in the correspondenting sal version
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/sal/version.rb', line 107 def Version.file_to_td(file_version) case file_version when 26 "1.1" when 27 "1.5" when 28 "2.0" # "2.1" when 31 "3.0" when 32 "3.1" when 34 "4.0" when 35 "4.1" # "4.2" when 37 "5.1" else raise "Version:file_to_td(#{file_version}): Version not analyzable." end end |
.from_code(code) ⇒ Object
Get the version from the code and returns a version object (fabric-method)
25 26 27 |
# File 'lib/sal/version.rb', line 25 def Version.from_code(code) Version.new(self.file_version_from_code(code)) end |
.from_file(file) ⇒ Object
Get the version from a file and returns a version object (fabric-method)
30 31 32 33 |
# File 'lib/sal/version.rb', line 30 def Version.from_file(file) code = IO.binread file Version.from_code code end |
.td_to_file(td_version) ⇒ Object
Convert the sal version in the correspondenting file version
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/sal/version.rb', line 77 def Version.td_to_file(td_version) case td_version when "1.1" 26 when "1.5" 27 when "2.0" 28 when "2.1" 28 when "3.0" 31 when "3.1" 32 when "4.0" 34 when "4.1" 35 when "4.2" 35 when "5.0" 37 when "5.1" 37 else raise "Version:td_to_file(#{td_version}): Version not analyzable." end end |
Instance Method Details
#to_code(code) ⇒ Object
Set the file version in the code to the file version of this object.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/sal/version.rb', line 48 def to_code(code) format = Format.get_from_code code if format == Format::NORMAL raise "Version.set_to_code: Code length to small!" if code.length < 5 code[4] = case file when 26 "\xfa" # Team Developer 1.1 when 27 "\xfb" # Team Developer 1.5 when 28 "\xfc" # Team Developer 2.0/2.1 when 31 "\xff" # Team Developer 3.0 when 32 "\x00" # Team Developer 3.1 when 34 "\x02" # Team Developer 4.0 when 35 "\x03" # Team Developer 4.1/4.2 else raise "Version.to_code: Version not settable: #{@file}/#{@td}" end else code.sub!(/(Outline Version - \d\.\d\.)(\d\d)/m, '\1' + file.to_s) end code end |
#to_file(filename) ⇒ Object
Set the fileversion of the file
Nothing else is changed. The source code can then be opend from the tool with the set version.
39 40 41 42 43 44 45 |
# File 'lib/sal/version.rb', line 39 def to_file(filename) code = IO.binread filename code = to_code(code, @file) f = File.new(filename, "w") f.syswrite code f.close end |