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
113
114
115
|
# File 'lib/itest5ch/thread.rb', line 113
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
89
90
91
92
93
94
95
|
# File 'lib/itest5ch/thread.rb', line 84
def self.normalize_message(message)
message =
begin
coder.decode(message)
rescue RangeError
message.gsub(/&#\d+;/, "")
end
message = 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
118
119
120
|
# File 'lib/itest5ch/thread.rb', line 118
def fetch_name
fetch_data["thread"][5]
end
|
#json_url ⇒ String
123
124
125
|
# File 'lib/itest5ch/thread.rb', line 123
def json_url
"http://itest.5ch.net/public/newapi/client.php?subdomain=#{subdomain}&board=#{board}&dat=#{dat}&rand=#{rand}"
end
|
#pc_url ⇒ String
108
109
110
|
# File 'lib/itest5ch/thread.rb', line 108
def pc_url
"http://#{subdomain}.5ch.net/test/read.cgi/#{board}/#{dat}"
end
|
#smartphone_url ⇒ String
103
104
105
|
# File 'lib/itest5ch/thread.rb', line 103
def smartphone_url
"http://itest.5ch.net/#{subdomain}/test/read.cgi/#{board}/#{dat}"
end
|