Class: Pluto::Model::Item

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.latestObject



24
25
26
27
28
29
30
# File 'lib/pluto/models/item.rb', line 24

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



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

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

#debug?Boolean

Returns:

  • (Boolean)


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

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

#descObject

alias (2) for summary – also add descr shortcut??



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

def desc()        summary;  end

#descriptionObject

alias for summary – also add descr shortcut??



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

def description() summary;  end

alias for url



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

def link()        url;      end

#nameObject

attribute reader aliases



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

def name()        title;    end

#publishedObject



34
35
36
37
38
39
40
41
42
# File 'lib/pluto/models/item.rb', line 34

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)


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

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

#update_from_struct!(feed_rec, data) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/pluto/models/item.rb', line 49

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 ? strip_tags(data.title)[0...255] : data.title,   ## limit to 255 chars; strip tags
    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