Module: Watir::AttributeHelper
- Included in:
- Element
- Defined in:
- lib/watir/attribute_helper.rb
Overview
Extended by Element, provides methods for defining attributes on the element classes.
Instance Method Summary collapse
-
#attribute(type, method, attr) ⇒ type
YARD macro to generated friendly documentation for attributes.
- #attribute_list ⇒ Object (also: #attributes)
- #define_attribute(type, name, attr) ⇒ Object
- #define_boolean_attribute(mname, aname) ⇒ Object
- #define_float_attribute(mname, aname) ⇒ Object
- #define_int_attribute(mname, aname) ⇒ Object
- #define_string_attribute(mname, aname) ⇒ Object
- #inherit_attributes_from(kls) ⇒ Object
-
#method ⇒ type
YARD macro to generated friendly documentation for attributes.
- #typed_attributes ⇒ Object
Instance Method Details
#attribute(type, method, attr) ⇒ type
YARD macro to generated friendly documentation for attributes.
50 51 52 53 54 55 |
# File 'lib/watir/attribute_helper.rb', line 50 def attribute(type, method, attr) return if method_defined?(method) typed_attributes[type] << [method, attr] define_attribute(type, method, attr) end |
#attribute_list ⇒ Object Also known as: attributes
32 33 34 35 36 37 38 |
# File 'lib/watir/attribute_helper.rb', line 32 def attribute_list @attribute_list ||= (typed_attributes.values.flatten + ancestors[1..].filter_map { |e| e.attribute_list if e.respond_to?(:attribute_list) }.flatten ).uniq end |
#define_attribute(type, name, attr) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/watir/attribute_helper.rb', line 57 def define_attribute(type, name, attr) case type.to_s when 'Boolean' define_boolean_attribute(name, attr) when 'Integer' define_int_attribute(name, attr) when 'Float' define_float_attribute(name, attr) else define_string_attribute(name, attr) end end |
#define_boolean_attribute(mname, aname) ⇒ Object
76 77 78 79 80 |
# File 'lib/watir/attribute_helper.rb', line 76 def define_boolean_attribute(mname, aname) define_method mname do attribute_value(aname) == 'true' end end |
#define_float_attribute(mname, aname) ⇒ Object
89 90 91 92 93 94 95 |
# File 'lib/watir/attribute_helper.rb', line 89 def define_float_attribute(mname, aname) define_method mname do value = attribute_value(aname) value = nil if value == 'NaN' value && Float(value) end end |
#define_int_attribute(mname, aname) ⇒ Object
82 83 84 85 86 87 |
# File 'lib/watir/attribute_helper.rb', line 82 def define_int_attribute(mname, aname) define_method mname do value = attribute_value(aname) value && Integer(value) end end |
#define_string_attribute(mname, aname) ⇒ Object
70 71 72 73 74 |
# File 'lib/watir/attribute_helper.rb', line 70 def define_string_attribute(mname, aname) define_method mname do attribute_value(aname).to_s end end |
#inherit_attributes_from(kls) ⇒ Object
22 23 24 25 26 |
# File 'lib/watir/attribute_helper.rb', line 22 def inherit_attributes_from(kls) kls.typed_attributes.each do |type, attrs| attrs.each { |method, attr| attribute type, method, attr } end end |
#method ⇒ type
YARD macro to generated friendly documentation for attributes.
50 51 52 53 54 55 |
# File 'lib/watir/attribute_helper.rb', line 50 def attribute(type, method, attr) return if method_defined?(method) typed_attributes[type] << [method, attr] define_attribute(type, method, attr) end |
#typed_attributes ⇒ Object
28 29 30 |
# File 'lib/watir/attribute_helper.rb', line 28 def typed_attributes @typed_attributes ||= Hash.new { |hash, type| hash[type] = [] } end |