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.



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

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

Instance Attribute Details

#nowObject (readonly)

Returns the value of attribute now.



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

def now
  @now
end

#session_idObject (readonly)

Returns the value of attribute session_id.



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

def session_id
  @session_id
end

#sourceObject (readonly)

Returns the value of attribute source.



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

def source
  @source
end

Class Method Details

.from_hash(data) ⇒ Object



116
117
118
# File 'lib/ruby_app/element.rb', line 116

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

Instance Method Details

#add_class(selector, _class) ⇒ Object



79
80
81
# File 'lib/ruby_app/element.rb', line 79

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

#alert(message) ⇒ Object



55
56
57
# File 'lib/ruby_app/element.rb', line 55

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

#confirm_refresh(message) ⇒ Object



63
64
65
# File 'lib/ruby_app/element.rb', line 63

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

#execute(statement) ⇒ Object



103
104
105
# File 'lib/ruby_app/element.rb', line 103

def execute(statement)
  @statements << statement
end

#go(url) ⇒ Object



95
96
97
# File 'lib/ruby_app/element.rb', line 95

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

#hide_dialog(dialog) ⇒ Object



71
72
73
# File 'lib/ruby_app/element.rb', line 71

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

#log(message) ⇒ Object



51
52
53
# File 'lib/ruby_app/element.rb', line 51

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

#process!Object



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

def process!
  raise RubyApp::Exceptions::SessionInvalidException.new(RubyApp::Request.POST['session_id']) unless self.session_id == RubyApp::Session.session_id
  source.send(:on_event, self)
end

#refreshObject



59
60
61
# File 'lib/ruby_app/element.rb', line 59

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

#remove_class(selector, _class) ⇒ Object



83
84
85
# File 'lib/ruby_app/element.rb', line 83

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


99
100
101
# File 'lib/ruby_app/element.rb', line 99

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(dialog) ⇒ Object



67
68
69
# File 'lib/ruby_app/element.rb', line 67

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

#to_hashObject



107
108
109
110
111
112
113
114
# File 'lib/ruby_app/element.rb', line 107

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

#todayObject



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

def today
  @now.send(:to_date)
end

#update_element(element) ⇒ Object



75
76
77
# File 'lib/ruby_app/element.rb', line 75

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

#update_text(selector, value) ⇒ Object



87
88
89
# File 'lib/ruby_app/element.rb', line 87

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

#update_value(selector, value) ⇒ Object



91
92
93
# File 'lib/ruby_app/element.rb', line 91

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