Class: Scrapbox::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/scrapbox/project.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, host = 'https://scrapbox.io') ⇒ Project

Returns a new instance of Project.



6
7
8
9
10
11
# File 'lib/scrapbox/project.rb', line 6

def initialize(name,host='https://scrapbox.io')
  @name = name
  @host = host
  @titles = nil
  @pages = nil
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



4
5
6
# File 'lib/scrapbox/project.rb', line 4

def host
  @host
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/scrapbox/project.rb', line 4

def name
  @name
end

Instance Method Details

#pagesObject



23
24
25
26
27
28
29
30
31
32
# File 'lib/scrapbox/project.rb', line 23

def pages
  unless @pages
    @pages = {}
    titles.each { |title|
      page = Scrapbox::Page.new(self,title)
      @pages[title] = page
    }
  end
  @pages
end

#titlesObject



13
14
15
16
17
18
19
20
21
# File 'lib/scrapbox/project.rb', line 13

def titles
  data = Scrapbox.__getsbdata("#{@host}/api/pages/#{@name}")
  unless @titles
    @titles = JSON.parse(data)['pages'].collect { |page|
      page['title']
    }
  end
  @titles
end