shortn-url 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/shortn-url.rb +4 -1
  2. metadata +1 -1
@@ -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[full_url='']")[0]
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shortn-url
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors: []
7
7