Class: Rubeechat::InfoList

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/rubeechat/info_list.rb

Defined Under Namespace

Classes: Buffer

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, ptr = '') ⇒ InfoList

Returns a new instance of InfoList.



52
53
54
55
# File 'lib/rubeechat/info_list.rb', line 52

def initialize(name, ptr='')
  @name = name.to_s
  @p    = Weechat.infolist_get(@name, ptr, '')
end

Instance Attribute Details

#pObject (readonly)

Returns the value of attribute p.



36
37
38
# File 'lib/rubeechat/info_list.rb', line 36

def p
  @p
end

Class Method Details

.buffer(ptr) ⇒ Object

return a buffer object from information in infolist pointed to by ptr



46
47
48
49
50
# File 'lib/rubeechat/info_list.rb', line 46

def self.buffer(ptr)
  open(:buffer, ptr) do |info|
    Buffer.new(ptr, info.first)
  end
end

.open(name, ptr = '') ⇒ Object



38
39
40
41
42
43
# File 'lib/rubeechat/info_list.rb', line 38

def self.open(name, ptr='')
  obj = self.new(name, ptr)
  yield obj
ensure
  obj.close
end

Instance Method Details

#closeObject



57
58
59
60
61
62
# File 'lib/rubeechat/info_list.rb', line 57

def close
  return unless @p
  i, @p = @p , nil
  Weechat.infolist_free(i)
  nil
end

#eachObject



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/rubeechat/info_list.rb', line 64

def each
  while Weechat.infolist_next(@p) > 0
    hash = Weechat.infolist_fields(@p).split(',').inject({}) do |memo,str|
      ftype, name = str.split(':')

      next memo if name =~ /^localvar/

      if val = fetch_item(ftype, name)
        memo[name.to_sym] = val
      end

      memo
    end

    yield hash
  end
end

#firstObject

returns the first struct in the infolist



83
84
85
# File 'lib/rubeechat/info_list.rb', line 83

def first
  to_a.first  # inefficient!
end