Class: Murlsh::UrlResultSet
- Inherits:
-
Object
- Object
- Murlsh::UrlResultSet
- Defined in:
- lib/murlsh/url_result_set.rb
Instance Attribute Summary collapse
-
#filters ⇒ Object
readonly
Returns the value of attribute filters.
-
#order ⇒ Object
readonly
Returns the value of attribute order.
-
#page ⇒ Object
readonly
Returns the value of attribute page.
-
#per_page ⇒ Object
readonly
Returns the value of attribute per_page.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
Instance Method Summary collapse
- #conditions ⇒ Object
-
#initialize(query, page, per_page, filters = {}) ⇒ UrlResultSet
constructor
A new instance of UrlResultSet.
- #next_page ⇒ Object
- #offset ⇒ Object
- #prev_page ⇒ Object
- #results ⇒ Object
- #search_conditions ⇒ Object
- #total_entries ⇒ Object
- #total_pages ⇒ Object
Constructor Details
#initialize(query, page, per_page, filters = {}) ⇒ UrlResultSet
Returns a new instance of UrlResultSet.
7 8 9 10 |
# File 'lib/murlsh/url_result_set.rb', line 7 def initialize(query, page, per_page, filters={}) @query, @page, @per_page, @filters = query, page, per_page, filters @order = 'time DESC' end |
Instance Attribute Details
#filters ⇒ Object (readonly)
Returns the value of attribute filters.
66 67 68 |
# File 'lib/murlsh/url_result_set.rb', line 66 def filters @filters end |
#order ⇒ Object (readonly)
Returns the value of attribute order.
67 68 69 |
# File 'lib/murlsh/url_result_set.rb', line 67 def order @order end |
#page ⇒ Object (readonly)
Returns the value of attribute page.
64 65 66 |
# File 'lib/murlsh/url_result_set.rb', line 64 def page @page end |
#per_page ⇒ Object (readonly)
Returns the value of attribute per_page.
65 66 67 |
# File 'lib/murlsh/url_result_set.rb', line 65 def per_page @per_page end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
63 64 65 |
# File 'lib/murlsh/url_result_set.rb', line 63 def query @query end |
Instance Method Details
#conditions ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/murlsh/url_result_set.rb', line 16 def conditions @conditions ||= if filters[:content_type] result = if filters[:content_type].is_a?(String) ['content_type = ?', filters[:content_type]] else ['content_type IN (?)', filters[:content_type]] end unless search_conditions.empty? result[0] << " AND (#{search_conditions[0]})" result.push(*search_conditions[1..-1]) end result else search_conditions end end |
#next_page ⇒ Object
56 57 58 59 60 61 |
# File 'lib/murlsh/url_result_set.rb', line 56 def next_page unless instance_variable_defined?(:@next_page) @next_page = page + 1 if page < total_pages end @next_page end |
#offset ⇒ Object
42 |
# File 'lib/murlsh/url_result_set.rb', line 42 def offset; @offset ||= (page - 1) * per_page; end |
#prev_page ⇒ Object
49 50 51 52 53 54 |
# File 'lib/murlsh/url_result_set.rb', line 49 def prev_page unless instance_variable_defined?(:@prev_page) @prev_page = page - 1 if (2..total_pages) === page end @prev_page end |
#results ⇒ Object
44 45 46 47 |
# File 'lib/murlsh/url_result_set.rb', line 44 def results Murlsh::Url.all(:conditions => conditions, :order => order, :limit => per_page, :offset => offset) end |
#search_conditions ⇒ Object
12 13 14 |
# File 'lib/murlsh/url_result_set.rb', line 12 def search_conditions @search_conditions ||= Murlsh::SearchConditions.new(query).conditions end |
#total_entries ⇒ Object
34 35 36 |
# File 'lib/murlsh/url_result_set.rb', line 34 def total_entries @total_entries ||= Murlsh::Url.count(:conditions => conditions) end |
#total_pages ⇒ Object
38 39 40 |
# File 'lib/murlsh/url_result_set.rb', line 38 def total_pages @total_pages ||= [(total_entries / per_page.to_f).ceil, 1].max end |