Class: Saxxy::Event

Inherits:
Object
  • Object
show all
Includes:
Activatable
Defined in:
lib/saxxy/event.rb

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.

Author:

  • rubymaniac

Constant Summary

Constants included from Activatable

Activatable::DLEVEL_MIN

Instance Attribute Summary collapse

Attributes included from Activatable

#activation_rule

Instance Method Summary collapse

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

Parameters:



36
37
38
39
40
# File 'lib/saxxy/event.rb', line 36

def initialize(action)
  @action = action
  initialize_options
  initialize_activatable(action.activation_rule)
end

Instance Attribute Details

#actionNodeAction (readonly)

Returns the underlying NodeAction.

Returns:



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_options
    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 initialize_options
    @text = ""
    @element_name = nil
    @attributes = {}
  end
end

#attributesHash (readonly)

Returns the attributes of the matching node.

Returns:

  • (Hash)

    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_options
    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 initialize_options
    @text = ""
    @element_name = nil
    @attributes = {}
  end
end

#element_nameHash (readonly)

Returns the name of the matching node.

Returns:

  • (Hash)

    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_options
    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 initialize_options
    @text = ""
    @element_name = nil
    @attributes = {}
  end
end

#textString (readonly)

Returns the text under the matching node.

Returns:

  • (String)

    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_options
    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 initialize_options
    @text = ""
    @element_name = nil
    @attributes = {}
  end
end

Instance Method Details

#append_text(text) ⇒ Object

Appends the argument to the event’s text attribute

Parameters:



47
48
49
50
# File 'lib/saxxy/event.rb', line 47

def append_text(text)
  @text += text
  @text
end

#fireObject

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

Parameters:

  • attrs (Hash)

    the attributes to merge



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

Parameters:

  • name (String)

    the new element_name



66
67
68
# File 'lib/saxxy/event.rb', line 66

def set_element_name(name)
  @element_name = name
end