creative_rails_utilities 0.4.6 → 0.4.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0aeba2d7261337d8ead0a8589484c3810e09f77d
4
- data.tar.gz: 75c51fa09a75031047752e8dd7d4cf2993a6dd69
3
+ metadata.gz: a156e7e7a2f650eb2d1bca609e59b5001155804b
4
+ data.tar.gz: 76fae005a8e49f46b77e37d154d35962753944ca
5
5
  SHA512:
6
- metadata.gz: bcc93b4c92d8ea744b797a8b873380aebeff10e70635d062cc3f4f8a3feb977944f3cc6af06994368129cec73a45db9a9780758be3b10ee3073135b4589388f5
7
- data.tar.gz: 21dc974ec4b821762f23c6827c8b88a7dc1f6995aa854a6b8d89c4e1356ad91ed7e1a9c8de7c85849ace8744bef406bc8dccfe5e250986cfdba5c4239cd94467
6
+ metadata.gz: 5ec35aa7b310c410b5ca2985ec86c5a5745d26659e423cc8784c92a092ffbc0b83091702880dfb84f060ba12b9c0cd8f1f4166a540b6aa34d80fe1c557af87c2
7
+ data.tar.gz: 3f8827f4bbc6fbeeadf7c2cc0a8e472692b005ff23d35e246e69cf0691894cbdebe4fe10d6da258e86f65809a4a8a583af4af0e2dcaca06a3449a95abe56869e
data/CHANGELOG.md CHANGED
@@ -8,6 +8,10 @@ This project adheres to [Semantic Versioning](http://semver.org/).
8
8
  -
9
9
  ```
10
10
 
11
+ ## [0.4.7] - 2017-04-07
12
+ ### Added
13
+ - HostParser.domain
14
+
11
15
  ## [0.4.6] - 2016-12-06
12
16
  ### Added
13
17
  - Hash.sum
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
@@ -1,3 +1,3 @@
1
1
  module CreativeRailsUtilities
2
- VERSION = "0.4.6"
2
+ VERSION = "0.4.7"
3
3
  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.6
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: 2016-12-06 00:00:00.000000000 Z
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