Class: Firefox::ProfileIndex
- Inherits:
-
Object
- Object
- Firefox::ProfileIndex
- Defined in:
- lib/firefox/profile_index.rb
Constant Summary collapse
- DEFAULT_PATH =
ROOT_PATH.join('profiles.ini')
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#profiles ⇒ Object
readonly
Returns the value of attribute profiles.
Instance Method Summary collapse
-
#initialize(path: DEFAULT_PATH) ⇒ ProfileIndex
constructor
A new instance of ProfileIndex.
- #load ⇒ Object
- #profile?(name) ⇒ Boolean
Constructor Details
#initialize(path: DEFAULT_PATH) ⇒ ProfileIndex
Returns a new instance of ProfileIndex.
21 22 23 24 |
# File 'lib/firefox/profile_index.rb', line 21 def initialize(path: DEFAULT_PATH) @path = path @profiles = {} end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
19 20 21 |
# File 'lib/firefox/profile_index.rb', line 19 def path @path end |
#profiles ⇒ Object (readonly)
Returns the value of attribute profiles.
19 20 21 |
# File 'lib/firefox/profile_index.rb', line 19 def profiles @profiles end |
Instance Method Details
#load ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/firefox/profile_index.rb', line 26 def load() sections = [] section = nil File.open(@path).each do |line| if line.match(/^\[([^\]]+)\]/) title = $1 next if title == 'General' section = {} sections << section elsif !section.nil? && line.match(/^([^=]+)\s*=\s*(.*)/) key = $1 value = $2 section[key] = value end end profiles = {} sections.each do |section| name = section['Name'] path = Pathname.new(section['Path']) is_relative = section['IsRelative'] if is_relative == '1' path = ROOT_PATH.join(path) end profile = Profile.new(name, path) profiles[name] = profile end @profiles = profiles end |
#profile?(name) ⇒ Boolean
61 62 63 |
# File 'lib/firefox/profile_index.rb', line 61 def profile?(name) return @profiles.key? name end |