Class: Waw::WSpec::HTMLAnalysis::Tag
- Defined in:
- lib/waw/wspec/html_analysis/tag.rb
Overview
A tag helper class
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Tag attributes.
-
#match ⇒ Object
readonly
Result of the regexp matching applied to get this tag.
-
#name ⇒ Object
readonly
Name of the tag.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Returns the value of an attribute.
-
#[]=(key, value) ⇒ Object
Forces the value of an attribute.
-
#has_attribute?(name) ⇒ Boolean
Checks if this tags has a given attribute.
-
#initialize(match, name, attributes) ⇒ Tag
constructor
Creates a Tag instance.
-
#matches?(opts = {}) ⇒ Boolean
Checks if this tag matches a given attributes specification.
Constructor Details
#initialize(match, name, attributes) ⇒ Tag
Creates a Tag instance
18 19 20 |
# File 'lib/waw/wspec/html_analysis/tag.rb', line 18 def initialize(match, name, attributes) @match, @name, @attributes = match, name, attributes end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Tag attributes
15 16 17 |
# File 'lib/waw/wspec/html_analysis/tag.rb', line 15 def attributes @attributes end |
#match ⇒ Object (readonly)
Result of the regexp matching applied to get this tag
9 10 11 |
# File 'lib/waw/wspec/html_analysis/tag.rb', line 9 def match @match end |
#name ⇒ Object (readonly)
Name of the tag
12 13 14 |
# File 'lib/waw/wspec/html_analysis/tag.rb', line 12 def name @name end |
Instance Method Details
#[](key) ⇒ Object
Returns the value of an attribute
23 24 25 |
# File 'lib/waw/wspec/html_analysis/tag.rb', line 23 def [](key) attributes[key] end |
#[]=(key, value) ⇒ Object
Forces the value of an attribute
28 29 30 |
# File 'lib/waw/wspec/html_analysis/tag.rb', line 28 def []=(key, value) attributes[key] = value end |
#has_attribute?(name) ⇒ Boolean
Checks if this tags has a given attribute
33 34 35 |
# File 'lib/waw/wspec/html_analysis/tag.rb', line 33 def has_attribute?(name) attributes.has_key?(name) end |
#matches?(opts = {}) ⇒ Boolean
Checks if this tag matches a given attributes specification
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/waw/wspec/html_analysis/tag.rb', line 38 def matches?(opts = {}) return true if (opts.nil? or opts.empty?) opts.each_pair do |name, value| return false unless self.has_attribute?(name) case value when Regexp return false unless value =~ self[name] else return false unless value.to_s == self[name] end end true end |