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 ???


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

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

#dateObject

add convenience date attribute helpers / readers

- what to return if date is nil? - return nil or empty string or 'n/a' or '?' - why? why not?

date date_iso | date_iso8601 date_822 | date_rfc2822 | date_rfc822



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

def date()        updated; end

#date_822Object Also known as: date_rfc2822, date_rfc822



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

def date_822()    date ? date.rfc822 : ''; end

#date_isoObject Also known as: date_iso8601



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

def date_iso()    date ? date.iso8601 : ''; end

#debug?Boolean

Returns:

  • (Boolean)


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

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

#publishedObject



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

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

#published?Boolean

Returns:

  • (Boolean)


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

def published?() published.present?; end

#update_from_struct!(data) ⇒ Object



87
88
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
115
116
# File 'lib/pluto/models/item.rb', line 87

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)


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

def updated?()   updated.present?;   end