Class: Newsitem

Inherits:
Object
  • Object
show all
Includes:
Ish::Utils, Mongoid::Document, Mongoid::Timestamps, Mongoid::Votable
Defined in:
lib/newsitem.rb

Overview

require_relative ‘./mongoid/votable.rb’

Constant Summary collapse

:type_gallery
TYPE_PHOTO =
:type_photo
TYPE_REPORT =
:type_report
TYPE_VIDEO =
:type_video
PER_PAGE =
6

Constants included from Mongoid::Votable

Mongoid::Votable::VOTE_POINT

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Mongoid::Votable

#down_voter_ids, #down_votes_count, #up_voter_ids, #up_votes_count, #vote, #vote_value, #votes_count, #votes_point

Methods included from Ish::Utils

#export

Class Method Details

.from_params(item) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/newsitem.rb', line 59

def self.from_params item
  n = Newsitem.new
  n.descr = item[:descr]
  n.username = item[:username]

  unless item[:report_id].blank?
    n.report = Report.find item[:report_id]
  end

  unless item[:gallery_id].blank?
    n.gallery = Gallery.find item[:gallery_id]
  end

  n.partial_name = item.partial_name unless item.partial_name.blank?

  return n
end

Instance Method Details

#collect(export_object) ⇒ Object



91
92
93
94
95
96
# File 'lib/newsitem.rb', line 91

def collect export_object
  export_object[:galleries][gallery.id.to_s] = gallery.id.to_s if gallery
  export_object[:photos][photo.id.to_s] = photo.id.to_s if photo
  export_object[:reports][report.id.to_s] = report.id.to_s if report
  export_object[:videos][video.id.to_s] = video.id.to_s if video
end

#descriptionObject



26
27
28
# File 'lib/newsitem.rb', line 26

def description
  descr
end

#export_fieldsObject



77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/newsitem.rb', line 77

def export_fields
  %w|
    descr
    gallery_id
    image_path
    link_path
    map_id
    name
    photo_id
    report_id
    video_id
  |
end


15
16
17
# File 'lib/newsitem.rb', line 15

def gallery
  self.gallery_id ? Gallery.unscoped.find( self.gallery_id ) : nil
end

#item_typeObject



47
48
49
50
51
52
# File 'lib/newsitem.rb', line 47

def item_type
  return TYPE_GALLERY if gallery_id
  return TYPE_PHOTO   if photo_id
  return TYPE_REPORT  if report_id
  return TYPE_VIDEO   if video_id
end