Class: Pluto::Model::Item

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

Defined Under Namespace

Classes: Data

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.latestObject



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

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 1970-01-01 for now
  order( Arel.sql( "coalesce(items.updated,items.published,'1970-01-01') desc" ) )
end

Instance Method Details

#dataObject

use a different name for data - why? why not?

e.g. inner, internal, readonly or r, raw, table, direct, or ???


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

def data()   @data ||= Data.new( self ); end

#debug?Boolean

Returns:

  • (Boolean)


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

def debug?()  Pluto.config.debug?;  end

#update_from_struct!(data) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/pluto/models/item.rb', line 65

def update_from_struct!( data )

  logger = LogUtils::Logger.root

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

  update!( item_attribs )
end

#updatedObject

note:

only use fallback for updated, that is, updated (or published)
 do NOT use fallback for published / created    -- why? why not?


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

def updated()  read_attribute_w_fallbacks( :updated, :published ); end

#updated?Boolean

Returns:

  • (Boolean)


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

def updated?() updated.present?;  end