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



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



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

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

#destination_missing?Boolean



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

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

#digest?Boolean



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

def digest?
  !@digest.nil?
end

#in_room?Boolean



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

def in_room?
  !@room.nil?
end

#merge(options) ⇒ Object



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

def merge(options)
  #self if options.nil?
  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



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

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

#sasl?Boolean



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

def sasl?
  !@sasl.nil?
end

#to_sObject



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

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