Class: Foliokit::EventAction
- Inherits:
-
Object
- Object
- Foliokit::EventAction
- Includes:
- Modules::Element
- Defined in:
- lib/foliokit/event.rb
Instance Method Summary collapse
- #export(document, event) ⇒ Object
- #normalize_value(value) ⇒ Object
- #to_hash ⇒ Object
- #valid? ⇒ Boolean
Methods included from Modules::Element
Instance Method Details
#export(document, event) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/foliokit/event.rb', line 45 def export(document, event) node = Nokogiri::XML::Node.new("overlay-action", document) node["trigger"] = event.name node["action"] = selector node["delay"] = delay unless delay.nil? node["time"] = time unless time.nil? node["target"] = target unless target.nil? node["state"] = state unless state.nil? node["reverse-direction"] = "" if reverse_direction node["stop-at-end"] = "" if stop_at_end node["loop-count"] = loop_count unless loop_count.nil? node end |
#normalize_value(value) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/foliokit/event.rb', line 31 def normalize_value(value) if value == "true" true elsif value == "false" false elsif value =~ /^[0-9.]+$/ value.to_f elsif value =~ /^[0-9]+$/ value.to_i else value end end |
#to_hash ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/foliokit/event.rb', line 14 def to_hash Hash[element.attributes.map do |k, v| value = normalize_value(v.value) if ["target", "state"].include?(k) value = hashify(value) end [k, value] end] end |
#valid? ⇒ Boolean
24 25 26 27 28 29 |
# File 'lib/foliokit/event.rb', line 24 def valid? return false if target.present? and !package.(target) return false if state.present? and !package.(state) true end |