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.
10 11 12 |
# File 'lib/embiggen/shortener_list.rb', line 10 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.
8 9 10 |
# File 'lib/embiggen/shortener_list.rb', line 8 def domains @domains end |
Instance Method Details
#+(other) ⇒ Object
18 19 20 |
# File 'lib/embiggen/shortener_list.rb', line 18 def +(other) self.class.new(domains + other) end |
#<<(domain) ⇒ Object
22 23 24 25 26 |
# File 'lib/embiggen/shortener_list.rb', line 22 def <<(domain) domains << host_pattern(domain) self end |
#delete(domain) ⇒ Object
28 29 30 |
# File 'lib/embiggen/shortener_list.rb', line 28 def delete(domain) domains.delete(host_pattern(domain)) end |
#host_pattern(domain) ⇒ Object
34 35 36 |
# File 'lib/embiggen/shortener_list.rb', line 34 def host_pattern(domain) /\b#{domain}\z/i end |
#include?(uri) ⇒ Boolean
14 15 16 |
# File 'lib/embiggen/shortener_list.rb', line 14 def include?(uri) domains.any? { |domain| uri.host =~ domain } end |