Class: Saxxy::Event
Overview
An Event refers to a specific NodeAction and is what is registered when a NodeAction matches a specific node. Because a NodeAction may match more than one node many events, under this action, should get registered.
Constant Summary
Constants included from Activatable
Instance Attribute Summary collapse
-
#action ⇒ NodeAction
readonly
The underlying NodeAction.
-
#attributes ⇒ Hash
readonly
The attributes of the matching node.
-
#element_name ⇒ Hash
readonly
The name of the matching node.
-
#text ⇒ String
readonly
The text under the matching node.
Attributes included from Activatable
Instance Method Summary collapse
-
#append_text(text) ⇒ Object
Appends the argument to the event’s text attribute.
-
#fire ⇒ Object
Calls the action with the text, element_name, attributes.
-
#initialize(action) ⇒ Event
constructor
Initializes an Event with an associated NodeAction.
-
#merge_attributes(attrs) ⇒ Object
Merges the argument hash to the event’s attributes.
-
#set_element_name(name) ⇒ Object
Changes the element_name.
Methods included from Activatable
#activate_on, #deactivate_on, included, #initialize_activatable, #on_activation, #on_deactivation
Constructor Details
#initialize(action) ⇒ Event
Initializes an Event with an associated NodeAction
36 37 38 39 40 |
# File 'lib/saxxy/event.rb', line 36 def initialize(action) @action = action initialize_activatable(action.activation_rule) end |
Instance Attribute Details
#action ⇒ NodeAction (readonly)
Returns the underlying NodeAction.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/saxxy/event.rb', line 27 class Event include Activatable attr_reader :text, :attributes, :element_name, :action # Initializes an Event with an associated NodeAction # # @param action [NodeAction] this event's action # def initialize(action) @action = action initialize_activatable(action.activation_rule) end # Appends the argument to the event's text attribute # # @param text [NodeAction] the text to append # # @return text [String] the event's text def append_text(text) @text += text @text end # Merges the argument hash to the event's attributes # # @param attrs [Hash] the attributes to merge # # @return attributes [Hash] the event's attributes def merge_attributes(attrs) @attributes.merge!(attrs) end # Changes the element_name # # @param name [String] the new element_name # # @return element_name [String] the event's element_name def set_element_name(name) @element_name = name end # Calls the action with the text, element_name, attributes def fire action.call(text, element_name, attributes) end private def @text = "" @element_name = nil @attributes = {} end end |
#attributes ⇒ Hash (readonly)
Returns the attributes of the matching node.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/saxxy/event.rb', line 27 class Event include Activatable attr_reader :text, :attributes, :element_name, :action # Initializes an Event with an associated NodeAction # # @param action [NodeAction] this event's action # def initialize(action) @action = action initialize_activatable(action.activation_rule) end # Appends the argument to the event's text attribute # # @param text [NodeAction] the text to append # # @return text [String] the event's text def append_text(text) @text += text @text end # Merges the argument hash to the event's attributes # # @param attrs [Hash] the attributes to merge # # @return attributes [Hash] the event's attributes def merge_attributes(attrs) @attributes.merge!(attrs) end # Changes the element_name # # @param name [String] the new element_name # # @return element_name [String] the event's element_name def set_element_name(name) @element_name = name end # Calls the action with the text, element_name, attributes def fire action.call(text, element_name, attributes) end private def @text = "" @element_name = nil @attributes = {} end end |
#element_name ⇒ Hash (readonly)
Returns the name of the matching node.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/saxxy/event.rb', line 27 class Event include Activatable attr_reader :text, :attributes, :element_name, :action # Initializes an Event with an associated NodeAction # # @param action [NodeAction] this event's action # def initialize(action) @action = action initialize_activatable(action.activation_rule) end # Appends the argument to the event's text attribute # # @param text [NodeAction] the text to append # # @return text [String] the event's text def append_text(text) @text += text @text end # Merges the argument hash to the event's attributes # # @param attrs [Hash] the attributes to merge # # @return attributes [Hash] the event's attributes def merge_attributes(attrs) @attributes.merge!(attrs) end # Changes the element_name # # @param name [String] the new element_name # # @return element_name [String] the event's element_name def set_element_name(name) @element_name = name end # Calls the action with the text, element_name, attributes def fire action.call(text, element_name, attributes) end private def @text = "" @element_name = nil @attributes = {} end end |
#text ⇒ String (readonly)
Returns the text under the matching node.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/saxxy/event.rb', line 27 class Event include Activatable attr_reader :text, :attributes, :element_name, :action # Initializes an Event with an associated NodeAction # # @param action [NodeAction] this event's action # def initialize(action) @action = action initialize_activatable(action.activation_rule) end # Appends the argument to the event's text attribute # # @param text [NodeAction] the text to append # # @return text [String] the event's text def append_text(text) @text += text @text end # Merges the argument hash to the event's attributes # # @param attrs [Hash] the attributes to merge # # @return attributes [Hash] the event's attributes def merge_attributes(attrs) @attributes.merge!(attrs) end # Changes the element_name # # @param name [String] the new element_name # # @return element_name [String] the event's element_name def set_element_name(name) @element_name = name end # Calls the action with the text, element_name, attributes def fire action.call(text, element_name, attributes) end private def @text = "" @element_name = nil @attributes = {} end end |
Instance Method Details
#append_text(text) ⇒ Object
Appends the argument to the event’s text attribute
47 48 49 50 |
# File 'lib/saxxy/event.rb', line 47 def append_text(text) @text += text @text end |
#fire ⇒ Object
Calls the action with the text, element_name, attributes
71 72 73 |
# File 'lib/saxxy/event.rb', line 71 def fire action.call(text, element_name, attributes) end |
#merge_attributes(attrs) ⇒ Object
Merges the argument hash to the event’s attributes
57 58 59 |
# File 'lib/saxxy/event.rb', line 57 def merge_attributes(attrs) @attributes.merge!(attrs) end |
#set_element_name(name) ⇒ Object
Changes the element_name
66 67 68 |
# File 'lib/saxxy/event.rb', line 66 def set_element_name(name) @element_name = name end |