Class: Itest5ch::Board
- Inherits:
-
Object
- Object
- Itest5ch::Board
- Includes:
- HttpMethods
- Defined in:
- lib/itest5ch/board.rb
Instance Attribute Summary collapse
Class Method Summary collapse
-
.all ⇒ Hash<String, Array<Itest5ch::Board>>
Get all boards.
- .find(board_name) ⇒ Itest5ch::Board
- .find_category_boards(category_name) ⇒ Array<Itest5ch::Board>
Instance Method Summary collapse
- #==(other) ⇒ Boolean
-
#initialize(url, name: nil) ⇒ Board
constructor
A new instance of Board.
- #json_url ⇒ String
- #threads ⇒ Array<Itest5ch::Thread>
Methods included from HttpMethods
Constructor Details
#initialize(url, name: nil) ⇒ Board
Returns a new instance of Board.
15 16 17 18 |
# File 'lib/itest5ch/board.rb', line 15 def initialize(url, name: nil) @url = url @name = name end |
Instance Attribute Details
#name ⇒ String
11 12 13 |
# File 'lib/itest5ch/board.rb', line 11 def name @name end |
#url ⇒ String
7 8 9 |
# File 'lib/itest5ch/board.rb', line 7 def url @url end |
Class Method Details
.all ⇒ Hash<String, Array<Itest5ch::Board>>
Get all boards
57 58 59 |
# File 'lib/itest5ch/board.rb', line 57 def self.all BoardListPage.new.all end |
.find(board_name) ⇒ Itest5ch::Board
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>
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
23 24 25 |
# File 'lib/itest5ch/board.rb', line 23 def ==(other) other.is_a?(Board) && url == other.url && name == other.name end |
#json_url ⇒ 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 |
#threads ⇒ Array<Itest5ch::Thread>
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 |