Class: Pluto::Models::Feed

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ActiveRecordMethods

#read_attribute_w_fallbacks

Class Method Details

.latestObject



14
15
16
17
18
19
20
21
# File 'lib/pluto/models/feed.rb', line 14

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(last_published,'1971-01-01') desc" )
end

Instance Method Details

#built_atObject

legay attrib reader - depreciated - remove!!



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

def built_at()          built;          end

#debug=(value) ⇒ Object



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

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

#debug?Boolean

Returns:

  • (Boolean)


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

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

#descriptionObject

alias for summary – also add descr shortcut??



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

def description() summary;  end

#feedObject

alias for feed_url



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

def feed()        feed_url; end

#feed_urlObject



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

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

#feed_url?Boolean

Returns:

  • (Boolean)


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

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

#fetched_atObject

legay attrib reader - depreciated - remove!!



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

def fetched_at()        fetched;        end

#last_published_atObject

legay attrib reader - depreciated - remove!!



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

def last_published_at() last_published; end

alias for url



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

def link()        url;      end

#nameObject

attribute reader aliases



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

def name()        title;    end

#publishedObject



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

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)


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

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

#published_atObject

legay attrib reader - depreciated - remove!!



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

def published_at()      published;      end

#save_from_struct!(data) ⇒ Object



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

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



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

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

#title2Object



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

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

#title2?Boolean

Returns:

  • (Boolean)


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

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

#title?Boolean

Returns:

  • (Boolean)


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

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

#touched?Boolean

Returns:

  • (Boolean)


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

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

#touched_atObject

legay attrib reader - depreciated - remove!!



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

def touched_at()        touched;        end

#update_from_struct!(data) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/pluto/models/feed.rb', line 89

def update_from_struct!( data )
  feed_attribs = {
      format:       data.format,
      published:    data.published? ? data.published : nil,
      touched:      data.updated?   ? data.updated   : nil,
      built:        data.built?     ? data.built     : nil,
      summary:      data.summary?   ? data.summary   : nil,
      ### todo/fix: add/use
      # auto_title:     ???,
      # auto_url:       ???,
      # auto_feed_url:  ???,
      auto_title2:  data.title2?    ? data.title2    : nil,
      generator:    data.generator
    }

  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



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

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

#url?Boolean

Returns:

  • (Boolean)


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

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