pluto-models 1.3.0 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Manifest.txt +1 -0
- data/README.md +70 -0
- data/lib/pluto/models/feed.rb +35 -0
- data/lib/pluto/version.rb +1 -1
- data/test/test_filter.rb +58 -0
- data/test/test_helpers.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52da2d8bfe30ec7e531849507767e24a82d9e768
|
4
|
+
data.tar.gz: 3ad21aa0944f78a4aea8913bfe6a0fa2e200538a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4964db168547374f42d1a48c3a11c35dd8519115425cd33ae6b08752cacab00200da21333bf21aa5b5dea5fec6af8e45865694e58a78d514f7e86a3187f81b0
|
7
|
+
data.tar.gz: 95fac37ced095094ea37e766d4a129f4ff02f4a7e362d4186396091040133e835e169048dc589a493483e4d060da217621df8acd02f9740497e425d82c5e883c
|
data/Manifest.txt
CHANGED
data/README.md
CHANGED
@@ -10,6 +10,76 @@
|
|
10
10
|
|
11
11
|
## Usage
|
12
12
|
|
13
|
+
### Models
|
14
|
+
|
15
|
+
Site • Feed • Item • Subscription
|
16
|
+
|
17
|
+
#### Site
|
18
|
+
|
19
|
+
~~~
|
20
|
+
class Site
|
21
|
+
has_many :subscriptions
|
22
|
+
has_many :feeds, :through => :subscriptions
|
23
|
+
has_many :items, :through => :feeds
|
24
|
+
...
|
25
|
+
end
|
26
|
+
~~~
|
27
|
+
|
28
|
+
#### Feed
|
29
|
+
|
30
|
+
~~~
|
31
|
+
class Feed
|
32
|
+
has_many :items
|
33
|
+
has_many :subscriptions
|
34
|
+
has_many :sites, :through => :subscriptions
|
35
|
+
...
|
36
|
+
end
|
37
|
+
~~~
|
38
|
+
|
39
|
+
#### Item
|
40
|
+
|
41
|
+
~~~
|
42
|
+
class Item
|
43
|
+
belongs_to :feed
|
44
|
+
...
|
45
|
+
end
|
46
|
+
~~~
|
47
|
+
|
48
|
+
#### Subscription
|
49
|
+
|
50
|
+
~~~
|
51
|
+
class Subscription
|
52
|
+
belongs_to :site
|
53
|
+
belongs_to :feed
|
54
|
+
...
|
55
|
+
end
|
56
|
+
~~~
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
### Examples
|
61
|
+
|
62
|
+
~~~
|
63
|
+
DB_CONFIG = {
|
64
|
+
adapter: 'sqlite3',
|
65
|
+
database: './planet.db'
|
66
|
+
}
|
67
|
+
|
68
|
+
Pluto.connect( DB_CONFIG )
|
69
|
+
|
70
|
+
Pluto::Model::Item.latest.limit(10).each_with_index do |item,i|
|
71
|
+
puts "[#{i+1}] #{item.title}"
|
72
|
+
|
73
|
+
if item.content
|
74
|
+
puts item.content
|
75
|
+
elsif item.summary
|
76
|
+
puts item.summary
|
77
|
+
else
|
78
|
+
## warn: no content found
|
79
|
+
end
|
80
|
+
end
|
81
|
+
~~~
|
82
|
+
|
13
83
|
|
14
84
|
|
15
85
|
## Real World Usage
|
data/lib/pluto/models/feed.rb
CHANGED
@@ -74,12 +74,47 @@ class Feed < ActiveRecord::Base
|
|
74
74
|
def debug=(value) @debug = value; end
|
75
75
|
def debug?() @debug || false; end
|
76
76
|
|
77
|
+
|
78
|
+
def match_terms?( terms, text ) ### make helper method private - why? why not??
|
79
|
+
return false if text.blank? ## allow/guard against nil and empty string
|
80
|
+
|
81
|
+
terms.each do |term|
|
82
|
+
if /#{term}/i =~ text ## Note: lets ignore case (use i regex option)
|
83
|
+
return true
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
false # no term match found
|
88
|
+
end
|
89
|
+
|
90
|
+
|
91
|
+
|
77
92
|
def save_from_struct!( data )
|
78
93
|
|
79
94
|
update_from_struct!( data )
|
80
95
|
|
81
96
|
data.items.each do |item|
|
82
97
|
|
98
|
+
######
|
99
|
+
## check for filters (includes/excludes) if present
|
100
|
+
## for now just check for includes
|
101
|
+
##
|
102
|
+
if includes.present?
|
103
|
+
## split terms (allow comma,pipe) - do NOT use space; allows e.g. terms such as github pages
|
104
|
+
terms = includes.split( /\s*[,|]\s*/ )
|
105
|
+
## remove leading and trailing white spaces - check - still required when using \s* ??
|
106
|
+
terms = terms.map { |term| term.strip }
|
107
|
+
match = match_terms?( terms, item.title ) ||
|
108
|
+
match_terms?( terms, item.summary) ||
|
109
|
+
match_terms?( terms, item.content)
|
110
|
+
|
111
|
+
if match == false
|
112
|
+
puts "** SKIPPING | #{item.title}"
|
113
|
+
puts " no include terms match: #{terms.join('|')}"
|
114
|
+
next ## skip to next item
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
83
118
|
item_rec = Item.find_by_guid( item.guid )
|
84
119
|
if item_rec.nil?
|
85
120
|
item_rec = Item.new
|
data/lib/pluto/version.rb
CHANGED
data/test/test_filter.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
###
|
4
|
+
# to run use
|
5
|
+
# ruby -I ./lib -I ./test test/test_filter.rb
|
6
|
+
# or better
|
7
|
+
# rake test
|
8
|
+
|
9
|
+
require 'helper'
|
10
|
+
|
11
|
+
class TestFilter < MiniTest::Test
|
12
|
+
|
13
|
+
def test_includes
|
14
|
+
|
15
|
+
feed1 = Feed.create!(
|
16
|
+
key: 'test',
|
17
|
+
title: 'Test',
|
18
|
+
includes: 'test1,test2,github pages'
|
19
|
+
)
|
20
|
+
|
21
|
+
feed2 = Feed.create!(
|
22
|
+
key: 'test',
|
23
|
+
title: 'Test'
|
24
|
+
)
|
25
|
+
|
26
|
+
feed_data = FeedUtils::Feed.new
|
27
|
+
feed_data.title = 'Test'
|
28
|
+
feed_data.items = []
|
29
|
+
|
30
|
+
item_data = FeedUtils::Item.new
|
31
|
+
item_data.title = 'Test #1'
|
32
|
+
item_data.summary = 'Test'
|
33
|
+
item_data.content = 'Test'
|
34
|
+
|
35
|
+
feed_data.items << item_data
|
36
|
+
|
37
|
+
item_data = FeedUtils::Item.new
|
38
|
+
item_data.title = 'Test #2'
|
39
|
+
item_data.summary = "Test\nTest\nTest1"
|
40
|
+
item_data.content = 'Test'
|
41
|
+
|
42
|
+
feed_data.items << item_data
|
43
|
+
|
44
|
+
|
45
|
+
item_data = FeedUtils::Item.new
|
46
|
+
item_data.title = 'Test #3'
|
47
|
+
item_data.summary = "Test\nTest\nTest"
|
48
|
+
item_data.content = 'Test\nTest\nGitHub Pages'
|
49
|
+
|
50
|
+
feed_data.items << item_data
|
51
|
+
|
52
|
+
feed1.save_from_struct!( feed_data ) ## check w/ includes
|
53
|
+
## feed2.save_from_struct!( feed_data ) ## check w/o includes
|
54
|
+
|
55
|
+
assert true ## if we get here it should workd
|
56
|
+
end
|
57
|
+
|
58
|
+
end # class TestFilter
|
data/test/test_helpers.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pluto-models
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerald Bauer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: props
|
@@ -189,6 +189,7 @@ files:
|
|
189
189
|
- lib/pluto/schema.rb
|
190
190
|
- lib/pluto/version.rb
|
191
191
|
- test/helper.rb
|
192
|
+
- test/test_filter.rb
|
192
193
|
- test/test_helpers.rb
|
193
194
|
homepage: https://github.com/feedreader/pluto-models
|
194
195
|
licenses:
|
@@ -217,4 +218,5 @@ signing_key:
|
|
217
218
|
specification_version: 4
|
218
219
|
summary: pluto-models - planet schema 'n' models for easy (re)use
|
219
220
|
test_files:
|
221
|
+
- test/test_filter.rb
|
220
222
|
- test/test_helpers.rb
|