Class: StreamdeckProf::Profile

Inherits:
Object
  • Object
show all
Defined in:
lib/streamdeck_prof/profile.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(profile_dir) ⇒ Profile

Returns a new instance of Profile.



12
13
14
15
# File 'lib/streamdeck_prof/profile.rb', line 12

def initialize(profile_dir)
  @profile_dir = profile_dir
  @manifest = JSON.parse(File.read(manifest_path))
end

Instance Attribute Details

#manifestObject (readonly)

Returns the value of attribute manifest.



10
11
12
# File 'lib/streamdeck_prof/profile.rb', line 10

def manifest
  @manifest
end

#profile_dirObject (readonly)

Returns the value of attribute profile_dir.



10
11
12
# File 'lib/streamdeck_prof/profile.rb', line 10

def profile_dir
  @profile_dir
end

Instance Method Details

#actionsObject



37
38
39
40
41
42
43
44
# File 'lib/streamdeck_prof/profile.rb', line 37

def actions
  @actions ||= StreamdeckProf::ActionList.new.tap do |actions|
    actions_hash = actions.to_h
    manifest["Actions"].each do |key, value|
      actions_hash[key] = make_action(key, value)
    end
  end
end

#actions=(actions) ⇒ Object



46
47
48
# File 'lib/streamdeck_prof/profile.rb', line 46

def actions=(actions)
  @actions = actions || StreamdeckProf::ActionList.new
end

#app_identifierObject



29
30
31
# File 'lib/streamdeck_prof/profile.rb', line 29

def app_identifier
  manifest["AppIdentifier"]
end

#app_identifier=(app_identifier) ⇒ Object



33
34
35
# File 'lib/streamdeck_prof/profile.rb', line 33

def app_identifier=(app_identifier)
  manifest["AppIdentifier"] = app_identifier
end

#nameObject



21
22
23
# File 'lib/streamdeck_prof/profile.rb', line 21

def name
  manifest["Name"]
end

#name=(name) ⇒ Object



25
26
27
# File 'lib/streamdeck_prof/profile.rb', line 25

def name=(name)
  manifest["Name"] = name
end

#saveObject



50
51
52
53
54
# File 'lib/streamdeck_prof/profile.rb', line 50

def save
  sync_manifest
  @actions&.to_h&.each { |position_key, action| action.save(action_storage_path(position_key)) }
  File.write(manifest_path, JSON.dump(manifest))
end

#uuidObject



17
18
19
# File 'lib/streamdeck_prof/profile.rb', line 17

def uuid
  File.basename(profile_dir, ".sdProfile")
end