Class: BBS2ch::Board

Inherits:
Object
  • Object
show all
Defined in:
lib/bbs2ch/board.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, url) ⇒ Board

Returns a new instance of Board.



3
4
5
6
7
# File 'lib/bbs2ch/board.rb', line 3

def initialize(name, url)
  @name    = name
  @url     = url
  @threads = nil
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



9
10
11
# File 'lib/bbs2ch/board.rb', line 9

def name
  @name
end

#urlObject

Returns the value of attribute url.



9
10
11
# File 'lib/bbs2ch/board.rb', line 9

def url
  @url
end

Instance Method Details

#load_threadsObject



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/bbs2ch/board.rb', line 18

def load_threads
  body = Connection.new(url + '/subject.txt').response_body

  body.each_line.map { |line|
    line.chomp!

    title_end  = line.rindex(' ')
    dat, title = line[0...title_end].split('<>')
    res_count  = line[title_end + 1 .. -1][/[0-9]+/].to_i

    BBS2ch::Thread.new(title, "#{url}/dat/#{dat}", res_count)
  }
end

#threads(regex = nil) ⇒ Object



11
12
13
14
15
16
# File 'lib/bbs2ch/board.rb', line 11

def threads(regex = nil)
  @threads ||= load_threads
  return @threads unless regex

  @threads.select { |thread| thread.name.match(regex) }
end