Class: JabberTee::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/jabber-tee/configuration.rb

Constant Summary collapse

ATTRIBUTES =
[:username, :nick, :password, :anonymous, :room, :to]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = nil) ⇒ Configuration

Returns a new instance of Configuration.



38
39
40
41
42
43
# File 'lib/jabber-tee/configuration.rb', line 38

def initialize(options=nil)
  @username = @nick = @to = @room = @anonymous = @password = nil
  if !options.nil?
    merge(options)
  end
end

Instance Attribute Details

#nickObject (readonly)

Returns the value of attribute nick.



36
37
38
# File 'lib/jabber-tee/configuration.rb', line 36

def nick
  @nick
end

#roomObject (readonly)

Returns the value of attribute room.



36
37
38
# File 'lib/jabber-tee/configuration.rb', line 36

def room
  @room
end

#toObject (readonly)

Returns the value of attribute to.



36
37
38
# File 'lib/jabber-tee/configuration.rb', line 36

def to
  @to
end

#usernameObject (readonly)

Returns the value of attribute username.



36
37
38
# File 'lib/jabber-tee/configuration.rb', line 36

def username
  @username
end

Instance Method Details

#anonymous?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/jabber-tee/configuration.rb', line 58

def anonymous?
  !@anonymous.nil? && username.nil?
end

#destination_missing?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/jabber-tee/configuration.rb', line 66

def destination_missing?
  @room.nil? && @to.nil?
end

#in_room?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/jabber-tee/configuration.rb', line 62

def in_room?
  !@room.nil?
end

#merge(options = nil) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/jabber-tee/configuration.rb', line 45

def merge(options=nil)
  return self if options.nil?
  ATTRIBUTES.each do |attr|
    value = options[attr] || options[attr.to_s]
    instance_variable_set("@#{attr}", value) if value
  end
  self
end

#passwordObject



54
55
56
# File 'lib/jabber-tee/configuration.rb', line 54

def password
  @password ||= ask("#{username}: password: ") {|q| q.echo = false }
end