pluto-models 1.3.0 → 1.3.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6690b769ee8041814fe15af85acc647ced2c4f33
4
- data.tar.gz: 797c2054af4bc2975495e9a7ba61ddf922d5f770
3
+ metadata.gz: 52da2d8bfe30ec7e531849507767e24a82d9e768
4
+ data.tar.gz: 3ad21aa0944f78a4aea8913bfe6a0fa2e200538a
5
5
  SHA512:
6
- metadata.gz: 1dca815302f8ffffbb8902241bf4db7388a2b747839cf88ee7be68ce2dc392de935127e994b1428454229516cd0efcb169e08b17ac46e20fbaecd6e526263b23
7
- data.tar.gz: af2731d41d1837c7ea81f7ac466c2714ed421e9a8ae0897e5e7dd989c9055f26daf594ffeb0b7469f0a396521c2b7912f5e6b92c61c401e98bf3cc976e5a7d56
6
+ metadata.gz: d4964db168547374f42d1a48c3a11c35dd8519115425cd33ae6b08752cacab00200da21333bf21aa5b5dea5fec6af8e45865694e58a78d514f7e86a3187f81b0
7
+ data.tar.gz: 95fac37ced095094ea37e766d4a129f4ff02f4a7e362d4186396091040133e835e169048dc589a493483e4d060da217621df8acd02f9740497e425d82c5e883c
@@ -13,4 +13,5 @@ lib/pluto/models/utils.rb
13
13
  lib/pluto/schema.rb
14
14
  lib/pluto/version.rb
15
15
  test/helper.rb
16
+ test/test_filter.rb
16
17
  test/test_helpers.rb
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
@@ -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
@@ -4,7 +4,7 @@ module Pluto
4
4
 
5
5
  MAJOR = 1
6
6
  MINOR = 3
7
- PATCH = 0
7
+ PATCH = 1
8
8
  VERSION = [MAJOR,MINOR,PATCH].join('.')
9
9
 
10
10
  def self.version
@@ -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
@@ -2,7 +2,7 @@
2
2
 
3
3
  ###
4
4
  # to run use
5
- # ruby -I ./lib -I ./test test/test_rss.rb
5
+ # ruby -I ./lib -I ./test test/test_helpers.rb
6
6
  # or better
7
7
  # rake test
8
8
 
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.0
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-15 00:00:00.000000000 Z
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