url_incrementer 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/url_incrementer/version.rb +2 -2
- data/lib/url_incrementer.rb +62 -4
- metadata +2 -3
- data/.rspec +0 -2
@@ -1,3 +1,3 @@
|
|
1
1
|
module UrlIncrementer
|
2
|
-
VERSION = "0.0.
|
3
|
-
end
|
2
|
+
VERSION = "0.0.2"
|
3
|
+
end
|
data/lib/url_incrementer.rb
CHANGED
@@ -1,7 +1,65 @@
|
|
1
1
|
require "url_incrementer/version"
|
2
2
|
|
3
3
|
module UrlIncrementer
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
class Inc
|
5
|
+
attr_accessor :template, :type, :params, :page_size, :start_page, :offset, :page_num, :page_date, :current_url
|
6
|
+
|
7
|
+
def initialize(template, type=:offset, options = {})
|
8
|
+
self.template = template
|
9
|
+
self.type = type
|
10
|
+
self.page_size = options[:page_size]
|
11
|
+
self.offset = options[:offset] || 0
|
12
|
+
self.page_num = options[:page_num] || 0
|
13
|
+
self.page_date = options[:page_date] || Time.now
|
14
|
+
end
|
15
|
+
|
16
|
+
def update_counters
|
17
|
+
self.page_num += 1
|
18
|
+
self.offset += self.page_size
|
19
|
+
self.page_date += 1.day
|
20
|
+
end
|
21
|
+
|
22
|
+
def next
|
23
|
+
self.current_url = template % instance_variables_hash
|
24
|
+
self.update_counters # must be after the line above because of the initial URL creation
|
25
|
+
self.current_url
|
26
|
+
end
|
27
|
+
|
28
|
+
def instance_variables_hash
|
29
|
+
Hash[instance_variables.map { |name| [name.to_s.gsub('@', '').to_sym, instance_variable_get(name)] } ]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
=begin
|
36
|
+
|
37
|
+
class UrlIncrementer
|
38
|
+
|
39
|
+
attr_accessor :type, :template, :page_size, :start_page, :event_list_css, :current_url, :tempate
|
40
|
+
attr_writer :page_num, :page_date, :entries
|
41
|
+
|
42
|
+
def page_num ; @page_num.nil? ? (self.start_page.nil? ? 1 : self.start_page) : @page_num end
|
43
|
+
def page_date ; @page_date.nil? ? Time.now : @page_date end
|
44
|
+
def entries ; @entries.nil? ? [] : @entries end
|
45
|
+
def date_format_1; "%Y-%m-%d" end
|
46
|
+
def date_format_2; "%m/%d/%Y" end
|
47
|
+
def date_format_3; "%Y/%m" end
|
48
|
+
def start_date; Time.now end
|
49
|
+
def end_date; 6.months.from_now end
|
50
|
+
|
51
|
+
def last_modified
|
52
|
+
@last_modified ||= begin
|
53
|
+
entry = entries.reject {|e| e.published.nil? }.sort_by { |entry| entry.published if entry.published }.last
|
54
|
+
entry ? entry.published : nil
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def updated?
|
59
|
+
@updated
|
60
|
+
end
|
61
|
+
|
62
|
+
def new_entries
|
63
|
+
@new_entries ||= []
|
64
|
+
end
|
65
|
+
=end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: url_incrementer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-03-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -67,7 +67,6 @@ extensions: []
|
|
67
67
|
extra_rdoc_files: []
|
68
68
|
files:
|
69
69
|
- .gitignore
|
70
|
-
- .rspec
|
71
70
|
- Gemfile
|
72
71
|
- LICENSE.txt
|
73
72
|
- README.md
|
data/.rspec
DELETED