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

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



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/newsitem.rb', line 53

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



87
88
89
90
91
92
# File 'lib/newsitem.rb', line 87

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
# File 'lib/newsitem.rb', line 26

def description; descr; end

#export_fieldsObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/newsitem.rb', line 71

def export_fields
  %w|
    descr
    name

    image_path
    link_path

    map_id
    gallery_id
    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



44
45
46
47
48
49
# File 'lib/newsitem.rb', line 44

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