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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 92488f0410ca139c74373da2171a81e3e4f8fda0
4
- data.tar.gz: f2ddc5cc924e3758ba2946bfb018571e7b785005
3
+ metadata.gz: 1689cb5caf47813138c6c9062e2bbe96e1297ca8
4
+ data.tar.gz: 9e0a59cc4419792e8c9d520ce3a45a091f51c05d
5
5
  SHA512:
6
- metadata.gz: 8b4a6e3cebafdff3fa00079d6b99660e775d41a3cdcf6fb2d6c8d8df9336896e8c24c060f076512fc73622122e65e36f81e5cf53c2b48f97fa68c8c3d07bf2b5
7
- data.tar.gz: aa1d03f01268a57c92bff8cf2c492df0fcd2eba487e206de5c14f79ea3adeea701d67e948a877d4a5dd6d3685e3edc52f61218a9527987387520984d4aabca9e
6
+ metadata.gz: 7e1b01b7aaa2d4cbfd7c5de80a6ce8d2362888372848d00198d51dc9b16afbfd996caab911af5ea028b1323596221560f4e9052e51304896d60fe655e1201976
7
+ data.tar.gz: 3044fa0df3a73e779c0d20e72f856b46646843565076da432826c8b75c68b118d6199638fadf388b6fa517db597a4f484d79cd1fb27ee77d057c9f730de36c55
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.1
4
+ - 2.0.0
5
+ - 1.9.3
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Pathology
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/pathology.svg)](http://badge.fury.io/rb/pathology)
4
+ [![Build Status](https://travis-ci.org/mattgillooly/pathology.svg?branch=master)](https://travis-ci.org/mattgillooly/pathology)
5
+ [![Code Climate](https://codeclimate.com/github/mattgillooly/pathology.png)](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
 
@@ -6,7 +6,9 @@ module Pathology
6
6
  end
7
7
 
8
8
  def interpolate(values)
9
- values.reduce(@pattern) do |interpolated, value|
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
@@ -1,3 +1,3 @@
1
1
  module Pathology
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -7,7 +7,7 @@ describe Pathology::Template do
7
7
 
8
8
  let(:values) {
9
9
  {
10
- :date => Date.today,
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.1
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-05-24 00:00:00.000000000 Z
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