Class: Domle::Element

Inherits:
Rexle::Element
  • Object
show all
Defined in:
lib/domle.rb

Direct Known Subclasses

Script, Style

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = nil, value: nil, attributes: Attributes.new(parent: self), rexle: nil) ⇒ Element

Returns a new instance of Element.



58
59
60
61
62
63
64
# File 'lib/domle.rb', line 58

def initialize(name=nil, value: nil, \
                      attributes: Attributes.new(parent: self), rexle: nil)
  
  attributes.merge!(style: '') unless attributes.has_key? :style
  super(name, value: value, attributes: attributes, rexle: rexle)
  
end

Class Method Details

.attr2_accessor(*a) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/domle.rb', line 66

def self.attr2_accessor(*a)

  a.concat %i(id transform)
  a.concat %i(onmousemove onmousedown) # DOM events      
  
  a.each do |attribute|

    class_eval do

      define_method attribute.to_s.gsub('-','_').to_sym do 
        attributes[attribute]
      end

      define_method (attribute.to_s + '=').to_sym do |val|
        attributes[attribute] = val
        @rexle.refresh
        val
      end

    end
  end
end

Instance Method Details

#hotspot?(x, y) ⇒ Boolean

Returns:

  • (Boolean)


94
95
96
97
98
99
100
# File 'lib/domle.rb', line 94

def hotspot?(x,y)

  (boundary.first.is_a?(Array) ? boundary : [boundary]).all? do |box|
    x1, y1, x2, y2 = box
    (x1..x2).include? x and (y1..y2).include? y
  end
end

#styleObject



89
90
91
# File 'lib/domle.rb', line 89

def style()
  attributes.style(@rexle)
end