Class: Pluto::Model::Item

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.latestObject



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

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

  # note: if not updated,published use hardcoded 1971-01-01 for now
  order( "coalesce(items.updated,items.published,'1971-01-01') desc" )
end

Instance Method Details

#debug=(value) ⇒ Object



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

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

#debug?Boolean

Returns:

  • (Boolean)


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

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

#descObject

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



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

def desc()        summary;  end

#descriptionObject

alias for summary – also add descr shortcut??



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

def description() summary;  end

alias for url



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

def link()        url;      end

#nameObject

attribute reader aliases



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

def name()        title;    end

#publishedObject



42
43
44
45
46
# File 'lib/pluto/models/item.rb', line 42

def published
  ## todo/fix: use a new name - do NOT squeeze convenience lookup into existing
  #    db backed attribute
  read_attribute_w_fallbacks( :published, :updated )
end

#published?Boolean

note: published is basically an alias for created

Returns:

  • (Boolean)


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

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

#update_from_struct!(data) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/pluto/models/item.rb', line 53

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

  ## note: for now also strip ads in summary
  ##  fix/todo: summary (in the future) is supposed to be only plain vanilla text

  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.blank? ? data.summary : strip_ads( data.summary ).strip,
    content:      data.content.blank? ? data.content : strip_ads( data.content ).strip,
    updated:      data.updated,
    published:    data.published,
  }

  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

#updatedObject



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

def updated
  ## todo/fix: use a new name - do NOT squeeze convenience lookup into existing
  #    db backed attribute
  read_attribute_w_fallbacks( :updated, :published )
end

#updated?Boolean

Returns:

  • (Boolean)


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

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