cartography 0.0.1 → 0.0.2

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/cartography.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "cartography/version"
2
2
 
3
3
  module Cartography
4
- # Your code goes here...
4
+
5
5
  end
6
+ require "cartography/sitemap"
@@ -0,0 +1,45 @@
1
+ require 'nokogiri'
2
+ module Cartography
3
+ class Sitemap
4
+ def initialize(baseUrl, options = {})
5
+ @options = {}
6
+ @options.merge(options)
7
+ @baseUrl = baseUrl
8
+ @urls = []
9
+ end
10
+
11
+ # Returns an XML string of the sitemap
12
+ def to_s
13
+ builder = Nokogiri::XML::Builder.new do |xml|
14
+ xml.urlset(:xmlns=>"http://www.sitemaps.org/schemas/sitemap/0.9"){
15
+ @urls.each do |url|
16
+ xml.url{
17
+ xml.loc_ "#{@baseUrl}#{url[:url]}"
18
+ unless url[:lastmod].nil?
19
+ xml.lastmod url[:lastmod].to_s
20
+ end
21
+ unless url[:changefreq].nil?
22
+ xml.changefreq url[:changefreq].to_s
23
+ end
24
+ unless url[:priority].nil?
25
+ xml.priority url[:priority].to_s
26
+ end
27
+ }
28
+ end
29
+ }
30
+ end
31
+
32
+ return builder.to_xml
33
+ end
34
+
35
+ # writes an XML string of the sitemap to the specified file.
36
+ def to_file(path)
37
+ return
38
+ end
39
+
40
+ #Adds a url to the array of urls.
41
+ def add(url, lastmod = nil, changefreq = nil, priority = nil)
42
+ @urls << {:url => url, :lastmod => lastmod, :changefreq => changefreq, :priority => priority}
43
+ end
44
+ end
45
+ end
@@ -1,3 +1,3 @@
1
1
  module Cartography
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,11 @@
1
+ require 'test/unit'
2
+ require 'cartography'
3
+
4
+ class TestSitemap < Test::Unit::TestCase
5
+ def testAdd
6
+ assert_nothing_raised do
7
+ item = Cartography::Sitemap.new('http://google.com')
8
+ item.add('/search.json')
9
+ end
10
+ end
11
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cartography
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -41,7 +41,9 @@ files:
41
41
  - Rakefile
42
42
  - cartography.gemspec
43
43
  - lib/cartography.rb
44
+ - lib/cartography/sitemap.rb
44
45
  - lib/cartography/version.rb
46
+ - test/testSitemap.rb
45
47
  homepage: ''
46
48
  licenses: []
47
49
  post_install_message:
@@ -66,4 +68,5 @@ rubygems_version: 1.8.24
66
68
  signing_key:
67
69
  specification_version: 3
68
70
  summary: ''
69
- test_files: []
71
+ test_files:
72
+ - test/testSitemap.rb