seg 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (7) hide show
  1. checksums.yaml +4 -4
  2. data/.gems +1 -1
  3. data/CHANGELOG +4 -0
  4. data/README.md +33 -0
  5. data/lib/seg.rb +24 -13
  6. data/seg.gemspec +1 -1
  7. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0ccbd7a24bc5e538d0ff2972799e98217d24b941
4
- data.tar.gz: df849adc128a8ba17f2d5bd0828acb0b34f93688
3
+ metadata.gz: f25f1dea8441edea70194c8fd14b65b87a36b075
4
+ data.tar.gz: 5dfa12b3f90ee62f6ad0b8967aaedb5c41a573ab
5
5
  SHA512:
6
- metadata.gz: e673fc8d51af98744cdde4ab94f19969ad955309778989c501ef97debef8a172d10047536787eea857536a30ea8db3a215fadef33a449a968503d481f4b5e95e
7
- data.tar.gz: 8fdc3e2f086884130d7a059c809dc84ff63c26fcff435eea1d5eb92f0d2731dc1e8e02aa7195059629d441a056ab0ac69dba2d58ecdf2fe3ebf66406ede1a202
6
+ metadata.gz: 3b8538b53350f6f704306626db309d8c38984ef925c18abc8ac0acc5993ebed908189165f798a05c13ccd20be65b31a8ef2d3a109edc4ddecee03a685f7612f1
7
+ data.tar.gz: 6ec70617648a4be0a7251cd8534a5a835724dffaa278cbaef0292754521961ab9bb571d66deca7f44dd1c8c29c166d2b718a845ccf1499ff9c18d84b627df771
data/.gems CHANGED
@@ -1 +1 @@
1
- cutest -v 1.2.2
1
+ cutest -v 1.2.3
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ 1.1.0
2
+
3
+ * Add extract method
4
+
1
5
  1.0.0
2
6
 
3
7
  * Stable release
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(length)
45
- @path[@pos, length]
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(sym, store)
75
- return false if root?
85
+ def capture(key, store)
86
+ str = extract
76
87
 
77
- len = (@path.index(SLASH, @pos) || @size) - @pos
78
-
79
- store[sym] = @path[@pos, len]
80
- move(len)
81
-
82
- return true
88
+ if str
89
+ store[key] = str
90
+ return true
91
+ else
92
+ return false
93
+ end
83
94
  end
84
95
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "seg"
3
- s.version = "1.0.0"
3
+ s.version = "1.1.0"
4
4
  s.summary = %{Segment matcher for paths}
5
5
  s.description = %Q{Segment matcher for paths.}
6
6
  s.authors = ["Michel Martens"]
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.0.0
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-20 00:00:00.000000000 Z
11
+ date: 2016-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cutest