Class: Embiggen::ShortenerList
- Inherits:
-
Object
- Object
- Embiggen::ShortenerList
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/embiggen/shortener_list.rb
Instance Attribute Summary collapse
-
#domains ⇒ Object
readonly
Returns the value of attribute domains.
Instance Method Summary collapse
- #+(other) ⇒ Object
- #<<(domain) ⇒ Object
- #delete(domain) ⇒ Object
- #host_pattern(domain) ⇒ Object
- #include?(uri) ⇒ Boolean
-
#initialize(domains) ⇒ ShortenerList
constructor
A new instance of ShortenerList.
Constructor Details
#initialize(domains) ⇒ ShortenerList
Returns a new instance of ShortenerList.
11 12 13 |
# File 'lib/embiggen/shortener_list.rb', line 11 def initialize(domains) @domains = Set.new(domains.map { |domain| host_pattern(domain) }) end |
Instance Attribute Details
#domains ⇒ Object (readonly)
Returns the value of attribute domains.
9 10 11 |
# File 'lib/embiggen/shortener_list.rb', line 9 def domains @domains end |
Instance Method Details
#+(other) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/embiggen/shortener_list.rb', line 19 def +(other) other_patterns = if other.respond_to?(:domains) other.domains else Set.new(other.map { |d| host_pattern(d) }) end self.class.allocate.tap do |result| result.instance_variable_set(:@domains, domains | other_patterns) end end |
#<<(domain) ⇒ Object
31 32 33 34 35 |
# File 'lib/embiggen/shortener_list.rb', line 31 def <<(domain) domains << host_pattern(domain) self end |
#delete(domain) ⇒ Object
37 38 39 |
# File 'lib/embiggen/shortener_list.rb', line 37 def delete(domain) domains.delete(host_pattern(domain)) end |
#host_pattern(domain) ⇒ Object
43 44 45 |
# File 'lib/embiggen/shortener_list.rb', line 43 def host_pattern(domain) /\b#{Regexp.escape(domain)}\z/i end |
#include?(uri) ⇒ Boolean
15 16 17 |
# File 'lib/embiggen/shortener_list.rb', line 15 def include?(uri) domains.any? { |domain| uri.host =~ domain } end |