Class: Itest5ch::Board

Inherits:
Object
  • Object
show all
Includes:
HttpMethods
Defined in:
lib/itest5ch/board.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HttpMethods

#get_html, #get_json

Constructor Details

#initialize(url, name: nil) ⇒ Board

Returns a new instance of Board.

Parameters:

  • url (String)
  • name (String) (defaults to: nil)


15
16
17
18
# File 'lib/itest5ch/board.rb', line 15

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

Instance Attribute Details

#nameString

Returns:

  • (String)


11
12
13
# File 'lib/itest5ch/board.rb', line 11

def name
  @name
end

#urlString

Returns:

  • (String)


7
8
9
# File 'lib/itest5ch/board.rb', line 7

def url
  @url
end

Class Method Details

.allHash<String, Array<Itest5ch::Board>>

Get all boards

Returns:

  • (Hash<String, Array<Itest5ch::Board>>)

    key: category name, value: boards



57
58
59
# File 'lib/itest5ch/board.rb', line 57

def self.all
  BoardListPage.new.all
end

.find(board_name) ⇒ Itest5ch::Board

Parameters:

  • board_name (String)

    name or id

Returns:



71
72
73
74
# File 'lib/itest5ch/board.rb', line 71

def self.find(board_name)
  url = "#{Itest5ch::BoardListPage::BOARDS_URL}subback/#{board_name}"
  all.values.flatten.find {|board| board_name == board.name || url == board.url }
end

.find_category_boards(category_name) ⇒ Array<Itest5ch::Board>

Parameters:

  • category_name (String)

Returns:



64
65
66
# File 'lib/itest5ch/board.rb', line 64

def self.find_category_boards(category_name)
  all[category_name]
end

Instance Method Details

#==(other) ⇒ Boolean

Parameters:

Returns:

  • (Boolean)


23
24
25
# File 'lib/itest5ch/board.rb', line 23

def ==(other)
  other.is_a?(Board) && url == other.url && name == other.name
end

#json_urlString

Returns:

  • (String)


42
43
44
45
46
47
48
49
50
51
52
# File 'lib/itest5ch/board.rb', line 42

def json_url
  if (m = url.match(%r{^https?://itest\.5ch\.net/subback/(.+?)/?$}))
    return "http://itest.5ch.net/subbacks/#{m[1]}.json"
  end

  if (m = url.match(%r{^https?://.+\.5ch\.net/(.+?)/?$}))
    return "http://itest.5ch.net/subbacks/#{m[1]}.json"
  end

  raise "Unknown url: #{url}"
end

#threadsArray<Itest5ch::Thread>

Returns:



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/itest5ch/board.rb', line 28

def threads
  hash = get_json(json_url, referer: url)
  hash["threads"].map do |thread|
    board, dat = thread[3].split("/", 2)
    Itest5ch::Thread.new(
      subdomain: thread[2],
      board:     board,
      dat:       dat.to_i,
      name:      thread[5],
    )
  end
end