Class: Pluto::Models::Item

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ActiveRecordMethods

#read_attribute_w_fallbacks

Class Method Details

.latestObject



17
18
19
20
21
22
23
# File 'lib/pluto/models/item.rb', line 17

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_at use hardcoded 1971-01-01 for now
  order( "coalesce(items.published,items.touched,'1971-01-01') desc" )
end

Instance Method Details

#debug=(value) ⇒ Object



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

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

#debug?Boolean

Returns:

  • (Boolean)


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

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

#descriptionObject

alias for summary – also add descr shortcut??



14
# File 'lib/pluto/models/item.rb', line 14

def description() summary;  end

alias for url



15
# File 'lib/pluto/models/item.rb', line 15

def link()        url;      end

#nameObject

attribute reader aliases



13
# File 'lib/pluto/models/item.rb', line 13

def name()        title;    end

#publishedObject



27
28
29
30
31
32
33
34
35
# File 'lib/pluto/models/item.rb', line 27

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 RSS/ATOM)
  )
end

#published?Boolean

Returns:

  • (Boolean)


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

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

#update_from_struct!(feed_rec, data) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/pluto/models/item.rb', line 42

def update_from_struct!( feed_rec, data )
  ## check: new item/record?  not saved?  add guid
  #   otherwise do not add guid  - why? why not?

  item_attribs = {
    guid:         data.guid,   # todo: only add for new records???
    title:        data.title,
    url:          data.url,
    summary:      data.summary,
    content:      data.content,
    published:    data.published,
    touched:      data.updated,
    feed_id:      feed_rec.id,    # add feed_id fk_ref
    fetched:      feed_rec.fetched
  }

  if debug?
    puts "*** dump item_attribs w/ class types:"
    item_attribs.each do |key,value|
      next if [:summary,:content].include?( key )   # skip summary n content
      puts "  #{key}: >#{value}< : #{value.class.name}"
    end
  end

  update_attributes!( item_attribs )
end