Class: Gecko::Widget::Text

Inherits:
Gecko::Widget show all
Includes:
Enumerable
Defined in:
lib/gecko/widget/text.rb

Defined Under Namespace

Classes: Item

Instance Attribute Summary

Attributes inherited from Gecko::Widget

#data, #keys

Instance Method Summary collapse

Methods inherited from Gecko::Widget

#config, #config!, #on_update, #payload, #push_requests, #push_url, #update

Constructor Details

#initialize(*args, &block) ⇒ Text

Returns a new instance of Text.



30
31
32
33
# File 'lib/gecko/widget/text.rb', line 30

def initialize(*args, &block)
  super
  @items = []
end

Instance Method Details

#[](index) ⇒ Object



48
49
50
# File 'lib/gecko/widget/text.rb', line 48

def [](index)
  @items[index]
end

#[]=(index, *args) ⇒ Object



52
53
54
# File 'lib/gecko/widget/text.rb', line 52

def []=(index, *args)
  @items[index] = Item.new(*args)
end

#add(*args) ⇒ Object



44
45
46
# File 'lib/gecko/widget/text.rb', line 44

def add(*args)
  @items.push(Item.new(*args))
end

#data_payloadObject



60
61
62
63
64
# File 'lib/gecko/widget/text.rb', line 60

def data_payload
  {
    :item => self.map{ |item| {:text => item.text, :type => item.type} }
  }
end

#delete(index) ⇒ Object



56
57
58
# File 'lib/gecko/widget/text.rb', line 56

def delete(index)
  @items.delete_at(index)
end

#each(&block) ⇒ Object



40
41
42
# File 'lib/gecko/widget/text.rb', line 40

def each(&block)
  @items.each(&block)
end

#resetObject



35
36
37
38
# File 'lib/gecko/widget/text.rb', line 35

def reset
  @items.clear
  self
end