Module: Storify::ElementRepresentable

Includes:
Representable::JSON
Defined in:
lib/storify/element.rb

Instance Method Summary collapse

Instance Method Details

#to_sObject

meta.….highly variable



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/storify/element.rb', line 26

def to_s
  out = ''
  desc = ''
  aut = ''
  published = DateTime.parse(posted_at).to_date

  case type
  when 'image'
    desc = data.image.caption
    aut = data.respond_to?(:oembed) ? data.oembed.author_name : attribution.name
  when 'text'
    desc = data.text

    doc = Nokogiri::HTML(desc)
    desc = doc.xpath("//text()").to_s
    desc = desc.gsub(/&[a-z]+;/,'')
  else
    desc = data.send("#{type}".to_sym).description

    aut = source.username
    aut = "@" + aut if source.name.downcase == 'twitter'
  end

  case source.name.downcase
  when 'storify'
    out << "\n#{desc}\n"
    out << ('-' * desc.length) + "\n\n" if desc.length < 40
  when 'twitter'
    out << "[#{published.to_s}] #{aut}: #{permalink}\n"
  else
    out << "#{aut} [#{published.to_s}]: #{permalink}\n"
  end

  out
end