Class: Hubeye::Config::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/hubeye/config/parser.rb

Defined Under Namespace

Classes: ConfigParseError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_file, options = {}) {|_self| ... } ⇒ Parser

Returns a new instance of Parser.

Yields:

  • (_self)

Yield Parameters:



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/hubeye/config/parser.rb', line 9

def initialize(config_file, options={})
  opts = {:test => false}.merge options
  if opts[:test] then klass = StringIO else klass = File end
  klass.open(config_file) do |f|
    while line = f.gets
      line = line.strip
      next if line.empty?
      user_opts = line.split(':').map! {|o| o.strip}
      case user_opts[0]
      when "username"
        @username = user_opts[1]
      when "track"
        @default_track = get_comma_separated_values(user_opts[1])
      when "load repos"
        @load_repos = get_comma_separated_values(user_opts[1])
      when "oncearound"
        @oncearound = user_opts[1].to_i
        if @oncearound.zero?
          raise ConfigParseError.new "oncearound in hubeyerc is " \
            "#{user_opts[1]} but must be a number that is greater than 0"
        end
      when "load hooks"
        @load_hooks = get_comma_separated_values(user_opts[1])
      when "desktop notification"
        on_off = user_opts[1]
        @notification_wanted = case on_off
        when "off"
          false
        when "on"
          true
        else
          raise ConfigParseError.new "desktop notification in hubeyerc is " \
            "'#{on_off}' and is expected to be either on or off"
        end
      end
    end
  end
  yield self
end

Instance Attribute Details

#default_trackObject (readonly)

Returns the value of attribute default_track.



6
7
8
# File 'lib/hubeye/config/parser.rb', line 6

def default_track
  @default_track
end

#load_hooksObject (readonly)

Returns the value of attribute load_hooks.



6
7
8
# File 'lib/hubeye/config/parser.rb', line 6

def load_hooks
  @load_hooks
end

#load_reposObject (readonly)

Returns the value of attribute load_repos.



6
7
8
# File 'lib/hubeye/config/parser.rb', line 6

def load_repos
  @load_repos
end

#notification_wantedObject (readonly)

Returns the value of attribute notification_wanted.



6
7
8
# File 'lib/hubeye/config/parser.rb', line 6

def notification_wanted
  @notification_wanted
end

#oncearoundObject (readonly)

Returns the value of attribute oncearound.



6
7
8
# File 'lib/hubeye/config/parser.rb', line 6

def oncearound
  @oncearound
end

#usernameObject (readonly)

Returns the value of attribute username.



6
7
8
# File 'lib/hubeye/config/parser.rb', line 6

def username
  @username
end