Class: U3d::License
- Inherits:
-
Object
- Object
- U3d::License
- Defined in:
- lib/u3d/unity_license.rb
Constant Summary collapse
- LICENSES_DIR_MAC =
File.join("/", "Library", "Application Support", "Unity").freeze
- LICENSES_DIR_WINDOWS =
File.join("C:/ProgramData", "Unity").freeze
- LICENSES_DIR_LINUX =
File.join(ENV['HOME'], ".local", "share", "unity3d", "Unity").freeze
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
- #[](index) ⇒ Object
-
#initialize(path: nil, fields: nil) ⇒ License
constructor
A new instance of License.
-
#number ⇒ Object
petit cachotier va!.
Constructor Details
#initialize(path: nil, fields: nil) ⇒ License
Returns a new instance of License.
29 30 31 32 |
# File 'lib/u3d/unity_license.rb', line 29 def initialize(path: nil, fields: nil) @path = path @fields = fields || {} end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
27 28 29 |
# File 'lib/u3d/unity_license.rb', line 27 def path @path end |
Class Method Details
.from_path(path) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/u3d/unity_license.rb', line 49 def from_path(path) doc = REXML::Document.new(File.read(path)) fields = {} license = REXML::XPath.first(doc, "root/License") unless license.nil? fields = [] license.each_element_with_attribute("Value") do |e| fields << [e.name, e.attribute('Value').to_s] end end License.new(path: path, fields: fields.to_h) end |
.licenses ⇒ Object
62 63 64 65 66 67 |
# File 'lib/u3d/unity_license.rb', line 62 def licenses glob = File.join(licenses_dir, "*.ulf") Dir.glob(glob).map do |path| from_path(path) end end |
.licenses_dir ⇒ Object
69 70 71 72 73 |
# File 'lib/u3d/unity_license.rb', line 69 def licenses_dir return LICENSES_DIR_MAC if U3d::Helper.mac? return LICENSES_DIR_WINDOWS if U3d::Helper.windows? return LICENSES_DIR_LINUX if U3d::Helper.linux? end |
Instance Method Details
#[](index) ⇒ Object
34 35 36 |
# File 'lib/u3d/unity_license.rb', line 34 def [](index) @fields[index] end |
#number ⇒ Object
petit cachotier va!
39 40 41 42 |
# File 'lib/u3d/unity_license.rb', line 39 def number require 'base64' Base64.decode64(self['DeveloperData'])[4..-1] end |