Class: Pluto::Model::Feed

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
TextUtils::HypertextHelper
Defined in:
lib/pluto/models/feed.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.latestObject



20
21
22
23
24
25
26
27
# File 'lib/pluto/models/feed.rb', line 20

def self.latest
  # note: order by first non-null datetime field
  #   coalesce - supported by sqlite (yes), postgres (yes)

  # note: if not published, touched or built use hardcoded 1971-01-01 for now
  ## order( "coalesce(published,touched,built,'1971-01-01') desc" )
  order( "coalesce(feeds.last_published,'1971-01-01') desc" )
end

Instance Method Details

#debug=(value) ⇒ Object



66
# File 'lib/pluto/models/feed.rb', line 66

def debug=(value)  @debug = value;   end

#debug?Boolean

Returns:

  • (Boolean)


67
# File 'lib/pluto/models/feed.rb', line 67

def debug?()       @debug || false;  end

#descriptionObject

alias for summary – also add descr shortcut??



35
# File 'lib/pluto/models/feed.rb', line 35

def description() summary;  end

#feedObject

alias for feed_url



37
# File 'lib/pluto/models/feed.rb', line 37

def feed()        feed_url; end

#feed_urlObject



47
# File 'lib/pluto/models/feed.rb', line 47

def feed_url() read_attribute_w_fallbacks( :feed_url, :auto_feed_url ); end

#feed_url?Boolean

Returns:

  • (Boolean)


42
# File 'lib/pluto/models/feed.rb', line 42

def feed_url?()      read_attribute(:feed_url).present?;  end

alias for url



36
# File 'lib/pluto/models/feed.rb', line 36

def link()        url;      end

#nameObject

attribute reader aliases

todo: check if we can use alias_method :name, :title   - works for non-existing/on-demand-generated method too??


34
# File 'lib/pluto/models/feed.rb', line 34

def name()        title;    end

#publishedObject



54
55
56
57
58
59
60
61
62
63
# File 'lib/pluto/models/feed.rb', line 54

def published
  ## todo/fix: use a new name - do NOT squeeze convenience lookup into existing
  #    db backed attribute

  read_attribute_w_fallbacks(
     :published,  
     :touched,     # try touched (aka updated (ATOM))
     :built        # try build (aka lastBuildDate (RSS))
  )
end

#published?Boolean

Returns:

  • (Boolean)


50
# File 'lib/pluto/models/feed.rb', line 50

def published?()  read_attribute(:published).present?;  end

#save_from_struct!(data) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/pluto/models/feed.rb', line 69

def save_from_struct!( data )

  update_from_struct!( data )
  
  data.items.each do |item|

    item_rec = Item.find_by_guid( item.guid )
    if item_rec.nil?
      item_rec  = Item.new
      puts "** NEW | #{item.title}"
    else
      ## todo: check if any attribs changed
      puts "UPDATE | #{item.title}"
    end
    
    item_rec.debug = debug? ? true : false  # pass along debug flag
    item_rec.update_from_struct!( self, item )

  end  # each item
end

#titleObject



45
# File 'lib/pluto/models/feed.rb', line 45

def title()    read_attribute_w_fallbacks( :title,    :auto_title );    end

#title2Object



46
# File 'lib/pluto/models/feed.rb', line 46

def title2()   read_attribute_w_fallbacks( :title2,   :auto_title2 );   end

#title2?Boolean

Returns:

  • (Boolean)


41
# File 'lib/pluto/models/feed.rb', line 41

def title2?()        read_attribute(:title2).present?;    end

#title?Boolean

Returns:

  • (Boolean)


40
# File 'lib/pluto/models/feed.rb', line 40

def title?()         read_attribute(:title).present?;     end

#touched?Boolean

Returns:

  • (Boolean)


51
# File 'lib/pluto/models/feed.rb', line 51

def touched?()    read_attribute(:touched).present?;    end

#update_from_struct!(data) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/pluto/models/feed.rb', line 91

def update_from_struct!( data )

  ## todo: move to FeedUtils::Feed ??? why? why not??
  if data.generator
    generator_full = ''
    generator_full << data.generator
    generator_full << " @version=#{data.generator_version}"   if data.generator_version
    generator_full << " @uri=#{data.generator_uri}"           if data.generator_uri
  else
    generator_full = nil
  end

##
# todo:
##  strip all tags from title2
##  limit to 255 chars
## e.g. title2 such as this exist
##  This is a low-traffic announce-only list for people interested
##  in hearing news about Polymer (<a href="http://polymer-project.org">http://polymer-project.org</a>).
## The higher-traffic mailing list for all kinds of discussion is
##  <a href="https://groups.google.com/group/polymer-dev">https://groups.google.com/group/polymer-dev</a>


  feed_attribs = {
      format:       data.format,
      published:    data.published,
      touched:      data.updated,
      built:        data.built,
      summary:      data.summary,
      ### todo/fix: add/use
      # auto_title:     ???,
      # auto_url:       ???,
      # auto_feed_url:  ???,
      auto_title2:  data.title2 ? strip_tags(data.title2)[0...255] : data.title2,   # limit to 255 chars; strip tags
      generator:    generator_full
    }

  if debug?
      ## puts "*** dump feed_attribs:"
      ## pp feed_attribs
      puts "*** dump feed_attribs w/ class types:"
      feed_attribs.each do |key,value|
        puts "  #{key}: >#{value}< : #{value.class.name}"
      end
  end

  update_attributes!( feed_attribs )
end

#urlObject



44
# File 'lib/pluto/models/feed.rb', line 44

def url()      read_attribute_w_fallbacks( :url,      :auto_url );      end

#url?Boolean

Returns:

  • (Boolean)


39
# File 'lib/pluto/models/feed.rb', line 39

def url?()           read_attribute(:url).present?;       end