pathology 0.0.1 → 0.1.0
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/.travis.yml +5 -0
- data/README.md +4 -0
- data/lib/pathology/template.rb +3 -1
- data/lib/pathology/version.rb +1 -1
- data/spec/pathology/template_spec.rb +18 -1
- 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: 1689cb5caf47813138c6c9062e2bbe96e1297ca8
|
4
|
+
data.tar.gz: 9e0a59cc4419792e8c9d520ce3a45a091f51c05d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e1b01b7aaa2d4cbfd7c5de80a6ce8d2362888372848d00198d51dc9b16afbfd996caab911af5ea028b1323596221560f4e9052e51304896d60fe655e1201976
|
7
|
+
data.tar.gz: 3044fa0df3a73e779c0d20e72f856b46646843565076da432826c8b75c68b118d6199638fadf388b6fa517db597a4f484d79cd1fb27ee77d057c9f730de36c55
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# Pathology
|
2
2
|
|
3
|
+
[](http://badge.fury.io/rb/pathology)
|
4
|
+
[](https://travis-ci.org/mattgillooly/pathology)
|
5
|
+
[](https://codeclimate.com/github/mattgillooly/pathology)
|
6
|
+
|
3
7
|
Specify a template to be used for generating paths by replacing :tokens with values from a hash.
|
4
8
|
This can be handy if you want to generate dynamic filenames or URLs using runtime data and a configurable format.
|
5
9
|
|
data/lib/pathology/template.rb
CHANGED
@@ -6,7 +6,9 @@ module Pathology
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def interpolate(values)
|
9
|
-
values.
|
9
|
+
sorted_values = values.sort_by{|token, replacement| token.length}.reverse
|
10
|
+
|
11
|
+
sorted_values.reduce(@pattern) do |interpolated, value|
|
10
12
|
token, replacement = *value
|
11
13
|
interpolated.gsub(/:#{token}/, replacement.to_s)
|
12
14
|
end
|
data/lib/pathology/version.rb
CHANGED
@@ -7,7 +7,7 @@ describe Pathology::Template do
|
|
7
7
|
|
8
8
|
let(:values) {
|
9
9
|
{
|
10
|
-
:date => Date.
|
10
|
+
:date => Date.new(2014, 5, 24),
|
11
11
|
:topic => 'hello'
|
12
12
|
}
|
13
13
|
}
|
@@ -19,6 +19,23 @@ describe Pathology::Template do
|
|
19
19
|
"~/notes/2014-05-24/hello.txt"
|
20
20
|
)
|
21
21
|
end
|
22
|
+
|
23
|
+
context 'given multiple possible matches' do
|
24
|
+
let(:pattern) { "~/notes/:date_string/foo.txt" }
|
25
|
+
|
26
|
+
let(:values) {
|
27
|
+
{
|
28
|
+
:date => Date.new(2014, 5, 24),
|
29
|
+
:date_string => 'May_5_2014',
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
33
|
+
it 'selects the longest key that matches each interpolation variable' do
|
34
|
+
expect( subject.interpolate( values ) ).to eq(
|
35
|
+
"~/notes/May_5_2014/foo.txt"
|
36
|
+
)
|
37
|
+
end
|
38
|
+
end
|
22
39
|
end
|
23
40
|
|
24
41
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pathology
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Gillooly
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -62,6 +62,7 @@ extra_rdoc_files: []
|
|
62
62
|
files:
|
63
63
|
- ".gitignore"
|
64
64
|
- ".rspec"
|
65
|
+
- ".travis.yml"
|
65
66
|
- Gemfile
|
66
67
|
- LICENSE.txt
|
67
68
|
- README.md
|