Class: Droom::Scrap

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/droom/scrap.rb

Instance Method Summary collapse

Instance Method Details

#as_search_resultObject



74
75
76
77
78
79
80
81
# File 'app/models/droom/scrap.rb', line 74

def as_search_result
  {
    :type => 'scrap',
    :prompt => name,
    :value => name,
    :id => id
  }
end

#next_olderObject



87
88
89
# File 'app/models/droom/scrap.rb', line 87

def next_older
  Droom::Scrap.earlier_than(self).first
end

#next_youngerObject



83
84
85
# File 'app/models/droom/scrap.rb', line 83

def next_younger
  Droom::Scrap.later_than(self).first
end

#text_sizeObject



58
59
60
61
62
63
64
# File 'app/models/droom/scrap.rb', line 58

def text_size
  if l = body.length
    ((560.0/(1.4 * l+150.0)) + 0.25) / 1.5
  else
    1
  end
end

#url_with_protocolObject



66
67
68
# File 'app/models/droom/scrap.rb', line 66

def url_with_protocol
  body =~ /^https?:\/\// ? body : "http://#{body}"
end

#url_without_protocolObject



70
71
72
# File 'app/models/droom/scrap.rb', line 70

def url_without_protocol
  body.sub(/^https?:\/\//, '')
end

#wordinessObject



46
47
48
49
50
51
52
53
54
55
56
# File 'app/models/droom/scrap.rb', line 46

def wordiness
  if body.length < 48
    'word'
  elsif body.length < 320
    'phrase'
  elsif body.length < 800
    'paragraph'
  else
    'text'
  end
end