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.
31 32 33 34 |
# File 'lib/u3d/unity_license.rb', line 31 def initialize(path: nil, fields: nil) @path = path @fields = fields || {} end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
29 30 31 |
# File 'lib/u3d/unity_license.rb', line 29 def path @path end |
Class Method Details
.from_path(path) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/u3d/unity_license.rb', line 51 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
64 65 66 67 68 69 |
# File 'lib/u3d/unity_license.rb', line 64 def licenses glob = File.join(licenses_dir, "*.ulf") Dir.glob(glob).map do |path| from_path(path) end end |
.licenses_dir ⇒ Object
71 72 73 74 75 |
# File 'lib/u3d/unity_license.rb', line 71 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
36 37 38 |
# File 'lib/u3d/unity_license.rb', line 36 def [](index) @fields[index] end |
#number ⇒ Object
petit cachotier va!
41 42 43 44 |
# File 'lib/u3d/unity_license.rb', line 41 def number require 'base64' Base64.decode64(self['DeveloperData'])[4..-1] end |