Class: Weechat::Bar::Item

Inherits:
Object
  • Object
show all
Extended by:
Callbacks, Properties
Includes:
Pointer
Defined in:
lib/weechat/bar.rb

Instance Attribute Summary

Attributes included from Pointer

#ptr

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Properties::ClassMethods

#all, #apply_rtransformation, #apply_transformation, #init_properties, #known_integer_properties, #known_properties, #known_string_properties, #mappings, #rtransformations, #settable_properties, #transformations, #type

Methods included from Callbacks

call_callback, callbacks, compute_free_id, compute_free_id, register_callback, unique_id

Methods included from Pointer

#==, #hash, included, #inspect, #to_s

Constructor Details

#initialize(name, &build_callback) ⇒ Item

eigenclass



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/weechat/bar.rb', line 40

def initialize(name, &build_callback)
  id = self.class.compute_free_id
  @ptr = Weechat.bar_item_new(name, "bar_build_callback", id.to_s)
  if @ptr.empty?
    raise "Could not create bar item"
  end

  self.class.register_callback(
                               :build_callback => Callback.new(build_callback),
                               :ptr            => @ptr
                               )
end

Class Method Details

.call_build_callback(id, window) ⇒ Object



64
65
66
67
# File 'lib/weechat/bar.rb', line 64

def call_build_callback(id, window)
  window = Window.from_ptr(window)
  call_callback(id, :build_callback, window).to_s
end

.find(name) ⇒ Object Also known as: from_name



29
30
31
32
33
34
35
36
# File 'lib/weechat/bar.rb', line 29

def find(name)
  ptr = Weechat.bar_item_search(name)
  if !ptr.empty?
    from_ptr(ptr)
  else
    nil
  end
end

.itemsObject Also known as: all



20
21
22
23
24
25
26
# File 'lib/weechat/bar.rb', line 20

def items
  items = []
  Weechat::Infolist.parse("bar_item").each do |item|
    items << Item.find(item[:name])
  end
  items
end

Instance Method Details

#deleteObject Also known as: remove



57
58
59
60
# File 'lib/weechat/bar.rb', line 57

def delete
  # TODO mark deletion status
  Weechat.bar_item_remove(@ptr)
end

#updateObject



53
54
55
# File 'lib/weechat/bar.rb', line 53

def update
  Weechat.bar_item_update(@name)
end