Class: FAFuse::Gallery

Inherits:
Object
  • Object
show all
Defined in:
lib/fafuse/gallery.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Gallery

Returns a new instance of Gallery.



12
13
14
15
16
# File 'lib/fafuse/gallery.rb', line 12

def initialize(path)
  @path = path
  @slug = Gallery.match?(path)[1]
  @resource = RestClient::Resource.new("http://www.furaffinity.net/gallery/")
end

Instance Attribute Details

#pathObject

Returns the value of attribute path.



6
7
8
# File 'lib/fafuse/gallery.rb', line 6

def path
  @path
end

#slugObject

Returns the value of attribute slug.



6
7
8
# File 'lib/fafuse/gallery.rb', line 6

def slug
  @slug
end

Class Method Details

.match?(path) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/fafuse/gallery.rb', line 8

def self.match?(path)
  path.match(/^\/([^\.][^\/]+)\/gallery$/)
end

Instance Method Details

#contentObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/fafuse/gallery.rb', line 36

def content
  [].tap do |content|
    loop.with_index do |_, page|
      @gallery = Nokogiri::HTML(@resource[slug][page + 1].get.body)
      break if @gallery.text.include?("There are no submissions to list")
      
      pictures = @gallery.css("#gallery-gallery figcaption a").map do |link|
        if link['href'].match(/^\/view\/.+\/$/)
          link['href'].match(/^\/view\/(.+)\/$/)[1]
        end
      end.compact
      
      content.concat pictures
    end
  end
end

#exists?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/fafuse/gallery.rb', line 32

def exists?
  Helpers::fa_is_valid?(document)
end

#statObject



22
23
24
25
26
27
28
29
30
# File 'lib/fafuse/gallery.rb', line 22

def stat
  return RFuse::Stat.directory(0555, {
                                 :uid => 0,
                                 :gid => 0,
                                 :atime => Time.now,
                                 :mtime => Time.now,
                                 :size => 0
                               })
end

#valid?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/fafuse/gallery.rb', line 18

def valid?
  !!slug && slug[0] != "."
end