Class: RubyApp::Element::Event

Inherits:
Object
  • Object
show all
Extended by:
Mixins::TranslateMixin
Defined in:
lib/ruby_app/element.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Mixins::TranslateMixin

localize, translate

Constructor Details

#initialize(data = nil) ⇒ Event

Returns a new instance of Event.



30
31
32
33
34
35
36
37
38
39
# File 'lib/ruby_app/element.rb', line 30

def initialize(data = nil)
  if data
    @now = Time.parse(data['now'])
    @source = RubyApp::Element.get_element(data['source_id'])
  else
    @now = Time.now
    @source = nil
  end
  @statements = []
end

Instance Attribute Details

#nowObject (readonly)

Returns the value of attribute now.



28
29
30
# File 'lib/ruby_app/element.rb', line 28

def now
  @now
end

#sourceObject (readonly)

Returns the value of attribute source.



28
29
30
# File 'lib/ruby_app/element.rb', line 28

def source
  @source
end

Class Method Details

.from_hash(data) ⇒ Object



110
111
112
# File 'lib/ruby_app/element.rb', line 110

def self.from_hash(data)
  eval(data['_class']).new(data)
end

Instance Method Details

#add_class(selector, _class) ⇒ Object



73
74
75
# File 'lib/ruby_app/element.rb', line 73

def add_class(selector, _class)
  execute("RubyApp.addClass(#{selector.to_json}, #{_class.to_json});")
end

#alert(message) ⇒ Object



49
50
51
# File 'lib/ruby_app/element.rb', line 49

def alert(message)
  execute("RubyApp.alert(#{message.to_json});")
end

#confirm_refresh(message) ⇒ Object



57
58
59
# File 'lib/ruby_app/element.rb', line 57

def confirm_refresh(message)
  execute("RubyApp.confirm_refresh(#{message.to_json});")
end

#execute(statement) ⇒ Object



97
98
99
# File 'lib/ruby_app/element.rb', line 97

def execute(statement)
  @statements << statement
end

#go(url) ⇒ Object



89
90
91
# File 'lib/ruby_app/element.rb', line 89

def go(url)
  execute("RubyApp.go(#{url.to_json});")
end

#hide(dialog) ⇒ Object



65
66
67
# File 'lib/ruby_app/element.rb', line 65

def hide(dialog)
  execute("RubyApp.hide('#{dialog.element_id}');")
end

#process!Object



45
46
47
# File 'lib/ruby_app/element.rb', line 45

def process!
  source.send(:on_event, self)
end

#refreshObject



53
54
55
# File 'lib/ruby_app/element.rb', line 53

def refresh
  execute("RubyApp.refresh();")
end

#remove_class(selector, _class) ⇒ Object



77
78
79
# File 'lib/ruby_app/element.rb', line 77

def remove_class(selector, _class)
  execute("RubyApp.removeClass(#{selector.to_json}, #{_class.to_json});")
end


93
94
95
# File 'lib/ruby_app/element.rb', line 93

def set_cookie(name, value, expires = Time.now + 365*24*60*60)
  execute("RubyApp.setCookie(#{name.to_json}, #{value.to_json}, new Date(#{expires.year}, #{expires.month - 1}, #{expires.day}, #{expires.hour}, #{expires.min}, #{expires.sec}));")
end

#show(dialog) ⇒ Object



61
62
63
# File 'lib/ruby_app/element.rb', line 61

def show(dialog)
  execute("RubyApp.show('#{dialog.element_id}');")
end

#to_hashObject



101
102
103
104
105
106
107
108
# File 'lib/ruby_app/element.rb', line 101

def to_hash
  {
    '_class' => self.class.to_s,
    'now' => @now,
    'source_id' => @source ? @source.element_id : nil,
    'statements' => @statements
  }
end

#todayObject



41
42
43
# File 'lib/ruby_app/element.rb', line 41

def today
  @now.send(:to_date)
end

#update_element(element) ⇒ Object



69
70
71
# File 'lib/ruby_app/element.rb', line 69

def update_element(element)
  execute("RubyApp.updateElement('#{element.element_id}');")
end

#update_text(selector, value) ⇒ Object



81
82
83
# File 'lib/ruby_app/element.rb', line 81

def update_text(selector, value)
  execute("RubyApp.updateText(#{selector.to_json}, #{value.to_json});")
end

#update_value(selector, value) ⇒ Object



85
86
87
# File 'lib/ruby_app/element.rb', line 85

def update_value(selector, value)
  execute("RubyApp.updateValue(#{selector.to_json}, #{value.to_json});")
end