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.



56
57
58
59
# File 'lib/rubeechat/info_list.rb', line 56

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.



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

def p
  @p
end

Class Method Details

.buffer(ptr) ⇒ Object

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



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

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

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



42
43
44
45
46
47
# File 'lib/rubeechat/info_list.rb', line 42

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

Instance Method Details

#closeObject



61
62
63
64
65
66
# File 'lib/rubeechat/info_list.rb', line 61

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

#eachObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/rubeechat/info_list.rb', line 68

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



87
88
89
# File 'lib/rubeechat/info_list.rb', line 87

def first
  to_a.first  # inefficient!
end