Class: Razsell::Results
- Inherits:
-
Object
- Object
- Razsell::Results
- Defined in:
- lib/razsell/results.rb
Overview
This class returns the query results
Instance Attribute Summary collapse
-
#items ⇒ Object
Returns the value of attribute items.
-
#items_per_page ⇒ Object
Returns the value of attribute items_per_page.
-
#result_count ⇒ Object
Returns the value of attribute result_count.
Instance Method Summary collapse
- #add(feed) ⇒ Object
- #build_hash_from(item) ⇒ Object
- #has_more_pages? ⇒ Boolean
-
#initialize(feed) ⇒ Results
constructor
A new instance of Results.
- #item_count ⇒ Object
- #split_keywords(words) ⇒ Object
- #strip_cdata(str) ⇒ Object
Constructor Details
#initialize(feed) ⇒ Results
Returns a new instance of Results.
10 11 12 13 14 15 16 17 |
# File 'lib/razsell/results.rb', line 10 def initialize feed @start_index = 0 @items_per_page = 0 @result_count = 0 @items = [] populate_items feed end |
Instance Attribute Details
#items ⇒ Object
Returns the value of attribute items.
8 9 10 |
# File 'lib/razsell/results.rb', line 8 def items @items end |
#items_per_page ⇒ Object
Returns the value of attribute items_per_page.
8 9 10 |
# File 'lib/razsell/results.rb', line 8 def items_per_page @items_per_page end |
#result_count ⇒ Object
Returns the value of attribute result_count.
8 9 10 |
# File 'lib/razsell/results.rb', line 8 def result_count @result_count end |
Instance Method Details
#add(feed) ⇒ Object
19 20 21 |
# File 'lib/razsell/results.rb', line 19 def add feed populate_items feed end |
#build_hash_from(item) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/razsell/results.rb', line 27 def build_hash_from item { title: strip_cdata(item.at("title").inner_html), guid: item.at("guid").inner_html, pub_date: Time.parse(item.at("pubDate").inner_html), link: item.at("link").inner_html, author: item.at("author").inner_html, description: strip_cdata(item.at("media:description").inner_html), thumbnail_url: item.at("media:thumbnail")['url'], content_url: item.at("media:content")['url'], keywords: split_keywords(item.at("media:keywords").inner_html), rating: item.at("media:rating").inner_html } end |
#has_more_pages? ⇒ Boolean
50 51 52 53 |
# File 'lib/razsell/results.rb', line 50 def has_more_pages? return false unless (@start_index && @items_per_page && @result_count) (@start_index + @items_per_page) < @result_count end |
#item_count ⇒ Object
23 24 25 |
# File 'lib/razsell/results.rb', line 23 def item_count @items.length end |
#split_keywords(words) ⇒ Object
40 41 42 43 44 |
# File 'lib/razsell/results.rb', line 40 def split_keywords words return [] if (!words || words == "") words.split(",").map { |s| s.strip } end |
#strip_cdata(str) ⇒ Object
46 47 48 |
# File 'lib/razsell/results.rb', line 46 def strip_cdata str str[9..-4] end |