Class: Hokusai::Automation::Selector
- Inherits:
-
Object
- Object
- Hokusai::Automation::Selector
- Defined in:
- ui/src/hokusai/automation/selector.rb
Instance Attribute Summary collapse
-
#class_list ⇒ Object
readonly
Returns the value of attribute class_list.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
Instance Method Summary collapse
-
#initialize(node, id, classes) ⇒ Selector
constructor
A new instance of Selector.
- #matches(block) ⇒ Object
- #to_s(str = "") ⇒ Object
Constructor Details
#initialize(node, id, classes) ⇒ Selector
Returns a new instance of Selector.
5 6 7 8 9 |
# File 'ui/src/hokusai/automation/selector.rb', line 5 def initialize(node, id, classes) @node = node @id = id @class_list = classes || [] end |
Instance Attribute Details
#class_list ⇒ Object (readonly)
Returns the value of attribute class_list.
3 4 5 |
# File 'ui/src/hokusai/automation/selector.rb', line 3 def class_list @class_list end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'ui/src/hokusai/automation/selector.rb', line 3 def id @id end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
3 4 5 |
# File 'ui/src/hokusai/automation/selector.rb', line 3 def node @node end |
Instance Method Details
#matches(block) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'ui/src/hokusai/automation/selector.rb', line 11 def matches(block) if portal = block.node.portal ast = portal.ast matches = [[ast.type, node], [ast.id, id]].reduce(true) do |memo, (ast_property, target)| next memo if target.nil? target == ast_property && memo end return (class_list & ast.classes) == class_list && matches end false end |
#to_s(str = "") ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'ui/src/hokusai/automation/selector.rb', line 27 def to_s(str = "") classes_string = nil unless class_list.empty? classes_string = ".#{class_list.join(".")}" str << "#{node || ""}##{id || ""}#{classes_string || ""}" end str end |