creative_rails_utilities 0.4.6 → 0.4.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +8 -0
- data/lib/creative_rails_utilities/host_parser.rb +19 -0
- data/lib/creative_rails_utilities/version.rb +1 -1
- data/lib/creative_rails_utilities.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a156e7e7a2f650eb2d1bca609e59b5001155804b
|
4
|
+
data.tar.gz: 76fae005a8e49f46b77e37d154d35962753944ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ec35aa7b310c410b5ca2985ec86c5a5745d26659e423cc8784c92a092ffbc0b83091702880dfb84f060ba12b9c0cd8f1f4166a540b6aa34d80fe1c557af87c2
|
7
|
+
data.tar.gz: 3f8827f4bbc6fbeeadf7c2cc0a8e472692b005ff23d35e246e69cf0691894cbdebe4fe10d6da258e86f65809a4a8a583af4af0e2dcaca06a3449a95abe56869e
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -98,6 +98,14 @@ sum = {1 => 1, 2 => {a: 2, b: 3}, 3 => {x: {y: 1}} }
|
|
98
98
|
|
99
99
|
```
|
100
100
|
|
101
|
+
##### HostParser
|
102
|
+
This is a mongrel service class that works similar to the URI module.
|
103
|
+
Give it a host string as argument and it will allow you to get the naked domain from it.
|
104
|
+
|
105
|
+
```rb
|
106
|
+
HostParser.new("deep.nested.subdomain.google.com").domain #=> "google.com"
|
107
|
+
```
|
108
|
+
|
101
109
|
##### Numeric
|
102
110
|
|
103
111
|
```ruby
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class HostParser
|
2
|
+
|
3
|
+
self::HOST_VALIDITY_REGEX = %r'\A(?<subdomains>(?:\w+\.)*?)(?<domain>\w+\.\w{2,5})\z'.freeze
|
4
|
+
|
5
|
+
def initialize(host)
|
6
|
+
@host = host
|
7
|
+
end
|
8
|
+
|
9
|
+
def domain
|
10
|
+
@host[send(:class)::HOST_VALIDITY_REGEX]
|
11
|
+
|
12
|
+
return nil if $~.blank?
|
13
|
+
|
14
|
+
match_hash = $~.names.inject({}){|mem, capture| mem[capture] = $~[capture]; mem}
|
15
|
+
|
16
|
+
return match_hash["domain"]
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -9,6 +9,7 @@ require "creative_rails_utilities/error_helper" # higher because require order r
|
|
9
9
|
require "creative_rails_utilities/array"
|
10
10
|
require "creative_rails_utilities/date"
|
11
11
|
require "creative_rails_utilities/hash"
|
12
|
+
require "creative_rails_utilities/host_parser"
|
12
13
|
require "creative_rails_utilities/numeric"
|
13
14
|
require "creative_rails_utilities/object"
|
14
15
|
require "creative_rails_utilities/string"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: creative_rails_utilities
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Creative
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -175,6 +175,7 @@ files:
|
|
175
175
|
- lib/creative_rails_utilities/date.rb
|
176
176
|
- lib/creative_rails_utilities/error_helper.rb
|
177
177
|
- lib/creative_rails_utilities/hash.rb
|
178
|
+
- lib/creative_rails_utilities/host_parser.rb
|
178
179
|
- lib/creative_rails_utilities/numeric.rb
|
179
180
|
- lib/creative_rails_utilities/object.rb
|
180
181
|
- lib/creative_rails_utilities/railtie.rb
|