seg 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gems +1 -1
- data/CHANGELOG +4 -0
- data/README.md +33 -0
- data/lib/seg.rb +24 -13
- data/seg.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f25f1dea8441edea70194c8fd14b65b87a36b075
|
4
|
+
data.tar.gz: 5dfa12b3f90ee62f6ad0b8967aaedb5c41a573ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b8538b53350f6f704306626db309d8c38984ef925c18abc8ac0acc5993ebed908189165f798a05c13ccd20be65b31a8ef2d3a109edc4ddecee03a685f7612f1
|
7
|
+
data.tar.gz: 6ec70617648a4be0a7251cd8534a5a835724dffaa278cbaef0292754521961ab9bb571d66deca7f44dd1c8c29c166d2b718a845ccf1499ff9c18d84b627df771
|
data/.gems
CHANGED
@@ -1 +1 @@
|
|
1
|
-
cutest -v 1.2.
|
1
|
+
cutest -v 1.2.3
|
data/CHANGELOG
CHANGED
data/README.md
CHANGED
@@ -108,6 +108,39 @@ how to capture segment values:
|
|
108
108
|
=> {:foo=>"users", :bar=>42}
|
109
109
|
```
|
110
110
|
|
111
|
+
It is also possible to `extract` the next segment from the path.
|
112
|
+
The method `extract` returns the next segment, if available, or nil
|
113
|
+
otherwise:
|
114
|
+
|
115
|
+
```ruby
|
116
|
+
>> s = Seg.new("/users/42")
|
117
|
+
=> #<Seg ...>
|
118
|
+
|
119
|
+
>> s.prev
|
120
|
+
=> ""
|
121
|
+
|
122
|
+
>> s.curr
|
123
|
+
=> "/users/42"
|
124
|
+
|
125
|
+
>> s.extract
|
126
|
+
=> "users"
|
127
|
+
|
128
|
+
>> s.prev
|
129
|
+
=> "/users"
|
130
|
+
|
131
|
+
>> s.curr
|
132
|
+
=> "/42"
|
133
|
+
|
134
|
+
>> s.extract
|
135
|
+
=> "42"
|
136
|
+
|
137
|
+
>> s.prev
|
138
|
+
=> "/users/42"
|
139
|
+
|
140
|
+
>> s.curr
|
141
|
+
=> ""
|
142
|
+
```
|
143
|
+
|
111
144
|
Installation
|
112
145
|
------------
|
113
146
|
|
data/lib/seg.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
#
|
3
3
|
# Copyright (c) 2015 Michel Martens
|
4
|
-
#
|
4
|
+
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
# of this software and associated documentation files (the "Software"), to deal
|
7
7
|
# in the Software without restriction, including without limitation the rights
|
8
8
|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
9
|
# copies of the Software, and to permit persons to whom the Software is
|
10
10
|
# furnished to do so, subject to the following conditions:
|
11
|
-
#
|
11
|
+
#
|
12
12
|
# The above copyright notice and this permission notice shall be included in
|
13
13
|
# all copies or substantial portions of the Software.
|
14
|
-
#
|
14
|
+
#
|
15
15
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
16
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
17
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
@@ -41,8 +41,8 @@ class Seg
|
|
41
41
|
@path[@pos + index]
|
42
42
|
end
|
43
43
|
|
44
|
-
def subs(
|
45
|
-
@path[@pos,
|
44
|
+
def subs(len)
|
45
|
+
@path[@pos, len]
|
46
46
|
end
|
47
47
|
|
48
48
|
def move(offset)
|
@@ -53,6 +53,17 @@ class Seg
|
|
53
53
|
@pos >= @size
|
54
54
|
end
|
55
55
|
|
56
|
+
def extract
|
57
|
+
return nil if root?
|
58
|
+
|
59
|
+
len = (@path.index(SLASH, @pos) || @size) - @pos
|
60
|
+
res = subs(len)
|
61
|
+
|
62
|
+
move(len)
|
63
|
+
|
64
|
+
res
|
65
|
+
end
|
66
|
+
|
56
67
|
def consume(str)
|
57
68
|
return false if root?
|
58
69
|
|
@@ -71,14 +82,14 @@ class Seg
|
|
71
82
|
end
|
72
83
|
end
|
73
84
|
|
74
|
-
def capture(
|
75
|
-
|
85
|
+
def capture(key, store)
|
86
|
+
str = extract
|
76
87
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
88
|
+
if str
|
89
|
+
store[key] = str
|
90
|
+
return true
|
91
|
+
else
|
92
|
+
return false
|
93
|
+
end
|
83
94
|
end
|
84
95
|
end
|
data/seg.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: seg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michel Martens
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cutest
|