shortn-url 0.1.3 → 0.1.4
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.
- data/lib/shortn-url.rb +4 -1
- metadata +1 -1
data/lib/shortn-url.rb
CHANGED
@@ -9,6 +9,8 @@ class ShortnUrl
|
|
9
9
|
def initialize(opt={}, app_mgr=nil)
|
10
10
|
@filepath = opt[:filepath]
|
11
11
|
@doc = Nokogiri::XML(File.open(@filepath,'r').read)
|
12
|
+
node = @doc.xpath("urls/records/url[full_url='']")[0]
|
13
|
+
@next_id = node.attribute('id').value.to_i
|
12
14
|
end
|
13
15
|
|
14
16
|
# fetch the short url if it already exists otherwise use a new short url
|
@@ -16,11 +18,12 @@ class ShortnUrl
|
|
16
18
|
|
17
19
|
short_url = @doc.xpath("urls/records/url[full_url='#{s}']/short_url").text
|
18
20
|
if short_url.empty? then
|
19
|
-
node = @doc.xpath("urls/records/url[
|
21
|
+
node = @doc.xpath("urls/records/url[@id='#{@next_id.to_s}']")[0]
|
20
22
|
node.xpath('full_url')[0].content = s
|
21
23
|
|
22
24
|
node['last_modified'] = Time.now.to_s
|
23
25
|
save()
|
26
|
+
@next_id += 1
|
24
27
|
node.xpath('short_url').text
|
25
28
|
else
|
26
29
|
short_url
|