rss-motor 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -8,6 +8,12 @@
8
8
  CHANGE-LOG
9
9
  =====================================================================
10
10
  =====================================================================
11
+ Changes from v0.1.0 to v0.1.1
12
+ [+] The node-attrib search would become a hash-key as
13
+ 'node:attrib' instead of 'node'
14
+ [+] Handling types of arguments passed on to rss_hashr
15
+ [+] Fixing default value for node-attribs
16
+ =====================================================================
11
17
  Changes from v0.0.9 to v0.1.0
12
18
  [+] updating Rss::Motor.items to fetch also custom nodes or node-attribs
13
19
  =====================================================================
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rss-motor (0.0.8)
5
- xml-motor (>= 0.1.5)
4
+ rss-motor (0.1.0)
5
+ xml-motor (>= 0.1.6)
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
@@ -14,4 +14,4 @@ PLATFORMS
14
14
 
15
15
  DEPENDENCIES
16
16
  rss-motor!
17
- xml-motor (>= 0.1.5)
17
+ xml-motor (>= 0.1.6)
data/README CHANGED
@@ -28,7 +28,7 @@ An easy to use RSS library to get kickstarted with using RSS Feeds.
28
28
 
29
29
  [+] passing a single RSS Link and fetching array of all items, with hash of nodes
30
30
  puts Rss::Motor.rss_items 'http://news.ycombinator.com/rss', ['comments'], {'media:content' => 'url'}
31
- Output: [{'title1' => '....', ...}, {'title2' => '....', ...}, ...]
31
+ Output: [{'title1' => '....', ..., 'media:content:url' => '...'}, {'title2' => '....', ..., 'media:content:url' => '...'}, ...]
32
32
  This will fetch hash with set of node values per rss item, including node value for 'comment'; value for 'url' attribute for node 'media:content'
33
33
 
34
34
  [+] filtering items from multiple rss-links having any from set of given keywords
@@ -1,9 +1,9 @@
1
1
  module Rss
2
2
  module Proc
3
3
 
4
- def self.rss_hashr(items, more_nodes, more_node_keys)
4
+ def self.rss_hashr(items, more_nodes=[], more_node_keys={})
5
5
  rss_hash = []
6
- items.each_with_index do |item, idx|
6
+ [items].flatten.each_with_index do |item, idx|
7
7
  item_splitd = XMLMotor.splitter item
8
8
  item_tags = XMLMotor.indexify item_splitd
9
9
  title = XMLMotor.xmldata item_splitd, item_tags, 'title'
@@ -24,11 +24,13 @@ module Rss
24
24
  }
25
25
 
26
26
  [more_nodes].flatten.each do |node|
27
- rss_hash[idx][node] = XMLMotor.xmldata(item_splitd, item_tags, node).join
27
+ rss_hash[idx][node] = XMLMotor.xmldata(item_splitd, item_tags, node).join unless node.nil?
28
28
  end
29
29
 
30
- more_node_keys.each_pair do |node, key|
31
- rss_hash[idx][node] = XMLMotor.xmlattrib(key, item_splitd, item_tags, node).join
30
+ if more_node_keys.is_a? Hash
31
+ more_node_keys.each_pair do |node, key|
32
+ rss_hash[idx]["#{node}:#{key}"] = XMLMotor.xmlattrib(key, item_splitd, item_tags, node).join
33
+ end
32
34
  end
33
35
  end
34
36
  return rss_hash
@@ -1,5 +1,5 @@
1
1
  module Rss
2
2
  module Motor
3
- VERSION = "0.1.0"
3
+ VERSION = '0.1.1'
4
4
  end
5
5
  end
@@ -1,26 +1,68 @@
1
1
  require 'spec_helper.rb'
2
2
 
3
3
  describe Rss::Motor do
4
- before(:all) {
5
- @url = "http://example.com"
6
- }
7
4
 
8
- describe "rss_items" do
9
- before(:all) do
10
- @response = {
11
- 'title' => 'FooBar title',
5
+ before(:all) do
6
+ @rss_item = <<-RSS
7
+ <items><item>
8
+ <title>item2</title>
9
+ <link>some url_link</link>
10
+ <description>Lorem ipsum dolor sit amet.</description>
11
+ <author>Doctor Who</author>
12
+ <comments>no comment</comments>
13
+ <media:content size='8Bit'/>
14
+ </item></items>
15
+ RSS
16
+ @response = [{
17
+ 'title' => 'item2',
12
18
  'link' => 'some url_link',
19
+ 'guid' => '',
13
20
  'description' => 'Lorem ipsum dolor sit amet.',
14
- 'author' => 'Doctor Who'
15
- }
16
- Rss::WWW.stubs(:rss_channel).returns([""])
17
- Rss::Proc.stubs(:rss_hashr).returns(@response)
21
+ 'date' => '',
22
+ 'author' => 'Doctor Who',
23
+ 'enclosure' => ''
24
+ }]
25
+
26
+ @for_node = 'comments'
27
+ @response_for_node = {'comments' => 'no comment'}
28
+ @for_node_attrib = {'media:content' => 'size'}
29
+ @response_for_node_attrib = {'media:content:size' => '8Bit'}
30
+ @url = "http://example.com"
31
+ end
32
+
33
+ describe "rss_items" do
34
+ before(:each) do
35
+ Rss::WWW.stubs(:rss_channel).returns([@rss_item])
18
36
  end
19
37
 
20
- it "should return Array of Hashes" do
38
+ it "should return Array of Hashes for default-nodes" do
21
39
  data = Rss::Motor.rss_items(@url)
22
40
  data.should eq(@response)
23
41
  end
42
+
43
+ it "should return Array of Hashes for default-nodes and extra argument node" do
44
+ data = Rss::Motor.rss_items(@url, @for_node)
45
+ new_response = @response[0].merge @response_for_node
46
+ data.should eq([new_response])
47
+ end
48
+
49
+ it "should return Array of Hashes for default-nodes and extra argument nodes array" do
50
+ data = Rss::Motor.rss_items(@url, [@for_node])
51
+ new_response = @response[0].merge @response_for_node
52
+ data.should eq([new_response])
53
+ end
54
+
55
+ it "should return Array of Hashes for default-nodes and extra argument node's attribute hash" do
56
+ data = Rss::Motor.rss_items(@url, [], @for_node_attrib)
57
+ new_response = @response[0].merge @response_for_node_attrib
58
+ data.should eq([new_response])
59
+ end
60
+
61
+ it "should return Array of Hashes for default-nodes and extra argument nodes array" do
62
+ data = Rss::Motor.rss_items(@url, ['comments'], @for_node_attrib)
63
+ new_response = @response[0].merge(@response_for_node).merge @response_for_node_attrib
64
+ data.should eq([new_response])
65
+ end
24
66
  end
25
67
 
26
68
  describe "rss_grep" do
@@ -63,26 +105,30 @@ describe Rss::Motor do
63
105
  res = Rss::Motor.item_filter({"title" => "some value"}, "value")
64
106
  res.should eq(true)
65
107
  end
108
+
66
109
  it "should return true if filter value founded case-insensitive" do
67
110
  res = Rss::Motor.item_filter({"title" => "Some Value"}, "value")
68
111
  res.should eq(true)
69
112
  end
113
+
70
114
  it "should return false if filter value not founded" do
71
115
  res = Rss::Motor.item_filter({"title" => "some value"}, "lorem")
72
116
  res.should eq(false)
73
117
  end
118
+
74
119
  it "should return true if item is empty" do
75
120
  res = Rss::Motor.item_filter({}, "value")
76
121
  res.should eq(false)
77
122
  end
123
+
78
124
  it "should return false if filter is nil" do
79
125
  res = Rss::Motor.item_filter({"title" => "some value"}, nil)
80
126
  res.should eq(false)
81
127
  end
128
+
82
129
  it "should return false if filter is empty" do
83
130
  res = Rss::Motor.item_filter({"title" => "some value"}, " ")
84
131
  res.should eq(false)
85
132
  end
86
133
  end
87
-
88
134
  end
@@ -6,4 +6,32 @@ describe Rss::Proc do
6
6
  response = Rss::Proc.rss_hashr(data)
7
7
  response.should eq([{"title" => "FooBar", "link"=>"", "guid"=>"", "description"=>"", "date"=>"", "author"=>"", "enclosure"=>""}])
8
8
  end
9
- end
9
+
10
+ it "should returned Hash with required Node Value" do
11
+ data = '<item><title>FooBar</title><uuid>007</uuid></item>'
12
+ required_node = 'uuid'
13
+ response = Rss::Proc.rss_hashr(data, required_node)
14
+ response.should eq([{'title' => 'FooBar', 'link'=>'', 'guid'=>'', 'description'=>'', 'date'=>'', 'author'=>'', 'enclosure'=>'', 'uuid'=>'007'}])
15
+ end
16
+
17
+ it "should returned Hash with required Node Value's Attribute, 2nd arg as nil" do
18
+ data = '<item><title>FooBar</title><uu id="007"/></item>'
19
+ node_attrib = {'uu' => 'id'}
20
+ response = Rss::Proc.rss_hashr(data, nil, node_attrib)
21
+ response.should eq([{'title' => 'FooBar', 'link'=>'', 'guid'=>'', 'description'=>'', 'date'=>'', 'author'=>'', 'enclosure'=>'', 'uu:id'=>'007'}])
22
+ end
23
+
24
+ it "should returned Hash with required Node Value's Attribute, 2nd arg empty" do
25
+ data = '<item><title>FooBar</title><uu id="007"/></item>'
26
+ node_attrib = {'uu' => 'id'}
27
+ response = Rss::Proc.rss_hashr(data, [], node_attrib)
28
+ response.should eq([{'title' => 'FooBar', 'link'=>'', 'guid'=>'', 'description'=>'', 'date'=>'', 'author'=>'', 'enclosure'=>'', 'uu:id'=>'007'}])
29
+ end
30
+
31
+ it "should returned Hash with 3rd Argument (node-attrib) as non-hash" do
32
+ data = '<item><title>FooBar</title><uu id="007"/></item>'
33
+ node_attrib = nil
34
+ response = Rss::Proc.rss_hashr(data, [], node_attrib)
35
+ response.should eq([{'title' => 'FooBar', 'link'=>'', 'guid'=>'', 'description'=>'', 'date'=>'', 'author'=>'', 'enclosure'=>''}])
36
+ end
37
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rss-motor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-22 00:00:00.000000000 Z
12
+ date: 2012-09-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: xml-motor
16
- requirement: &7882920 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: 0.1.6
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *7882920
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 0.1.6
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: xml-motor
27
- requirement: &7882420 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,7 +37,12 @@ dependencies:
32
37
  version: 0.1.6
33
38
  type: :development
34
39
  prerelease: false
35
- version_requirements: *7882420
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 0.1.6
36
46
  description: ! 'boost up your RSS related applications with the motor available: https://github.com/abhishekkr/rubygem_rss_motor/blob/master/README'
37
47
  email:
38
48
  - abhikumar163@gmail.com
@@ -77,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
87
  version: '0'
78
88
  requirements: []
79
89
  rubyforge_project: rss-motor
80
- rubygems_version: 1.8.17
90
+ rubygems_version: 1.8.24
81
91
  signing_key:
82
92
  specification_version: 3
83
93
  summary: wanna use RSS in your code easily, its here to aid