Class: Twterm::Preferences

Inherits:
AbstractPersistableConfiguration show all
Defined in:
lib/twterm/preferences.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractPersistableConfiguration

#complete_missing_items!, has_same_structure?

Constructor Details

#initialize(preferences) ⇒ Preferences

Returns a new instance of Preferences.



7
8
9
# File 'lib/twterm/preferences.rb', line 7

def initialize(preferences)
  super(preferences)
end

Class Method Details

.defaultTwterm::Preferences

Returns an instance having the default value

Returns:



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/twterm/preferences.rb', line 28

def self.default
  new({
    photo_viewer_backend: {
      browser: true,
      imgcat: false,
      quick_look: false,
    },
    notification_backend: {
      inline: true,
      terminal_notifier: false,
      tmux: false,
    },
  })
end

.structureHash

Returns:

  • (Hash)


49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/twterm/preferences.rb', line 49

def self.structure
  bool = -> x { x == true || x == false }

  {
    photo_viewer_backend: {
      browser: bool,
      imgcat: bool,
      quick_look: bool,
    },
    notification_backend: {
      inline: bool,
      terminal_notifier: bool,
      tmux: bool,
    },
  }
end

Instance Method Details

#[](cat, key) ⇒ Object

Parameters:

  • cat (Symbol)
  • key (Symbol)


13
14
15
16
17
# File 'lib/twterm/preferences.rb', line 13

def [](cat, key)
  validate_key!(cat, key)

  configuration[cat][key]
end

#[]=(cat, key, value) ⇒ Object



19
20
21
22
23
# File 'lib/twterm/preferences.rb', line 19

def []=(cat, key, value)
  validate_key!(cat, key)

  configuration[cat][key] = value
end

#to_hHash

Returns:

  • (Hash)


44
45
46
# File 'lib/twterm/preferences.rb', line 44

def to_h
  configuration
end