Class: JabberTee::Configuration

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

Constant Summary collapse

ATTRIBUTES =
['username', 'nick', 'password', 'anonymous', 'sasl', 'digest', 'room', 'to']

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = nil) ⇒ Configuration

Returns a new instance of Configuration.



43
44
45
46
47
# File 'lib/jabber-tee/configuration.rb', line 43

def initialize(options=nil)
  if !options.nil?
    merge(options)
  end
end

Instance Attribute Details

#nickObject (readonly)

Returns the value of attribute nick.



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

def nick
  @nick
end

#roomObject (readonly)

Returns the value of attribute room.



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

def room
  @room
end

#toObject (readonly)

Returns the value of attribute to.



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

def to
  @to
end

#usernameObject (readonly)

Returns the value of attribute username.



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

def username
  @username
end

Instance Method Details

#anonymous?Boolean

Returns:

  • (Boolean)


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

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

#destination_missing?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/jabber-tee/configuration.rb', line 82

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

#digest?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/jabber-tee/configuration.rb', line 74

def digest?
  !@digest.nil?
end

#in_room?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/jabber-tee/configuration.rb', line 78

def in_room?
  !@room.nil?
end

#merge(options) ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'lib/jabber-tee/configuration.rb', line 49

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

#passwordObject



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

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

#sasl?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/jabber-tee/configuration.rb', line 70

def sasl?
  !@sasl.nil?
end

#to_sObject



86
87
88
# File 'lib/jabber-tee/configuration.rb', line 86

def to_s
  "<JabberTee::Configuration{:username => '#{username}', :room => '#{room}', :to => '#{to}', :anonymous => #{anonymous?}, :sasl => #{sasl?}}>"
end