Class: Itest5ch::Thread
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#assert_required!, #assert_required_keys!
#get_html, #get_json
Constructor Details
#initialize(subdomain: , board: , dat: , name: nil) ⇒ Thread
#initialize(url) ⇒ Thread
Returns a new instance of Thread.
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/itest5ch/thread.rb', line 47
def initialize(args)
case args
when Hash
initialize_with_hash(args)
when String
initialize_with_string(args)
else
raise ArgumentError, "args is either Hash or String is required"
end
end
|
Instance Attribute Details
#board ⇒ String
15
16
17
|
# File 'lib/itest5ch/thread.rb', line 15
def board
@board
end
|
#dat ⇒ Integer
19
20
21
|
# File 'lib/itest5ch/thread.rb', line 19
def dat
@dat
end
|
#name ⇒ String
106
107
108
|
# File 'lib/itest5ch/thread.rb', line 106
def name
@name ||= fetch_name
end
|
#subdomain ⇒ String
11
12
13
|
# File 'lib/itest5ch/thread.rb', line 11
def subdomain
@subdomain
end
|
Class Method Details
.normalize_message(message) ⇒ String
84
85
86
87
88
|
# File 'lib/itest5ch/thread.rb', line 84
def self.normalize_message(message)
message = coder.decode(message).scrub("")
message = CGI.unescapeHTML(message)
message.gsub(/\s*<br>\s*/i, "\n").strip
end
|
Instance Method Details
#==(other) ⇒ Boolean
61
62
63
64
|
# File 'lib/itest5ch/thread.rb', line 61
def ==(other)
other.is_a?(Thread) && subdomain == other.subdomain && board == other.board &&
dat == other.dat && name == other.name
end
|
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/itest5ch/thread.rb', line 67
def
fetch_data["comments"].map do ||
Comment.new(
number: [0].to_i,
name: [1],
mail: [2],
date: time_at([3].to_i),
id: [4],
message: self.class.normalize_message([6]),
thread: self,
)
end
end
|
#fetch_name ⇒ String
111
112
113
|
# File 'lib/itest5ch/thread.rb', line 111
def fetch_name
fetch_data["thread"][5]
end
|
#json_url ⇒ String
116
117
118
|
# File 'lib/itest5ch/thread.rb', line 116
def json_url
"http://itest.5ch.net/public/newapi/client.php?subdomain=#{subdomain}&board=#{board}&dat=#{dat}&rand=#{rand}"
end
|
#pc_url ⇒ String
101
102
103
|
# File 'lib/itest5ch/thread.rb', line 101
def pc_url
"http://#{subdomain}.5ch.net/test/read.cgi/#{board}/#{dat}"
end
|
#smartphone_url ⇒ String
96
97
98
|
# File 'lib/itest5ch/thread.rb', line 96
def smartphone_url
"http://itest.5ch.net/#{subdomain}/test/read.cgi/#{board}/#{dat}"
end
|