Class: StreamdeckProf::Context
- Inherits:
-
Object
- Object
- StreamdeckProf::Context
- Defined in:
- lib/streamdeck_prof/context.rb
Instance Method Summary collapse
- #default_profile ⇒ Object
-
#initialize(profiles_dir: default_profiles_dir) ⇒ Context
constructor
A new instance of Context.
- #new_profile(type: :xl) ⇒ Object
- #profile_by_name(name) ⇒ Object
- #profile_for_application(application, exact: true) ⇒ Object
- #profiles ⇒ Object
Constructor Details
#initialize(profiles_dir: default_profiles_dir) ⇒ Context
Returns a new instance of Context.
9 10 11 |
# File 'lib/streamdeck_prof/context.rb', line 9 def initialize(profiles_dir: default_profiles_dir) @profiles_dir = profiles_dir end |
Instance Method Details
#default_profile ⇒ Object
27 28 29 |
# File 'lib/streamdeck_prof/context.rb', line 27 def default_profile profile_for_application("*") end |
#new_profile(type: :xl) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/streamdeck_prof/context.rb', line 35 def new_profile(type: :xl) manifest = StreamdeckProf::DeviceData.const_get(type.upcase)[:empty_profile] uuid = SecureRandom.uuid.upcase profile_path = File.join(@profiles_dir, "#{uuid}.sdProfile") manifest_path = File.join(profile_path, "manifest.json") Dir.mkdir(profile_path) File.write(manifest_path, JSON.dump(manifest)) @profiles = nil Profile.new(profile_path) end |
#profile_by_name(name) ⇒ Object
31 32 33 |
# File 'lib/streamdeck_prof/context.rb', line 31 def profile_by_name(name) profiles.find { |p| p.name == name } end |
#profile_for_application(application, exact: true) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/streamdeck_prof/context.rb', line 19 def profile_for_application(application, exact: true) if exact profiles.find { |p| p.app_identifier == application } else profiles.find { |p| p.app_identifier&.include?(application) } end end |