Class: Fushin::Posts::Post

Inherits:
Object
  • Object
show all
Defined in:
lib/fushin/posts/post.rb

Direct Known Subclasses

Jugem, Kikey, Sblo, Seesaa, Shinobi, Teacup

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ Post

Returns a new instance of Post.



15
16
17
# File 'lib/fushin/posts/post.rb', line 15

def initialize(url)
  @url = url
end

Instance Attribute Details

#urlObject (readonly)

Returns the value of attribute url.



13
14
15
# File 'lib/fushin/posts/post.rb', line 13

def url
  @url
end

Instance Method Details

#attachementsObject



53
54
55
# File 'lib/fushin/posts/post.rb', line 53

def attachements
  []
end

#btcsObject



31
32
33
34
35
# File 'lib/fushin/posts/post.rb', line 31

def btcs
  @btcs ||= main.text.scan(/\b[13][a-km-zA-HJ-NP-Z0-9]{26,33}\b/).uniq.map do |address|
    Models::BTC.new(address)
  end
end


49
50
51
# File 'lib/fushin/posts/post.rb', line 49

def links
  @links ||= main.css("a").map { |a| a.get("href") }.compact.select { |link| link.start_with?("http://", "https://") }
end

#mainObject



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/fushin/posts/post.rb', line 19

def main
  @main ||= [].tap do |out|
    body = doc.at_css(main_selector)

    main_cleanup_selectors.each do |selector|
      body.css(selector).each(&:remove)
    end

    out << body
  end.first
end

#urlsObject



37
38
39
40
41
42
43
# File 'lib/fushin/posts/post.rb', line 37

def urls
  @urls ||= (urls_in_text + links).uniq.map do |url|
    next if whitelisted_domain?(url)

    Models::Website.new(url)
  end.compact.uniq(&:normalized_url)
end

#urls_in_textObject



45
46
47
# File 'lib/fushin/posts/post.rb', line 45

def urls_in_text
  @urls_in_text ||= main.text.scan(UrlRegex.get(scheme_required: true, mode: :parsing))
end