Class: Megalopolis::Novel
- Includes:
- Essentials
- Defined in:
- lib/megalopolis/scheme.rb
Instance Attribute Summary collapse
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#log ⇒ Object
readonly
Returns the value of attribute log.
-
#novel ⇒ Object
readonly
Returns the value of attribute novel.
Instance Method Summary collapse
- #comment(text, params = {}) ⇒ Object
- #fetch_novel(base_url, log, id) ⇒ Object
-
#initialize(base_url, log, id) ⇒ Novel
constructor
A new instance of Novel.
- #plain ⇒ Object
- #simple_rating(point) ⇒ Object
Methods included from Essentials
Methods inherited from MHash
Constructor Details
#initialize(base_url, log, id) ⇒ Novel
Returns a new instance of Novel.
26 27 28 29 30 31 32 |
# File 'lib/megalopolis/scheme.rb', line 26 def initialize(base_url, log, id) @novel = fetch_novel(base_url, log, id) @base_url = base_url @log = log @id = id super(@novel) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Megalopolis::MHash
Instance Attribute Details
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
22 23 24 |
# File 'lib/megalopolis/scheme.rb', line 22 def base_url @base_url end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
24 25 26 |
# File 'lib/megalopolis/scheme.rb', line 24 def id @id end |
#log ⇒ Object (readonly)
Returns the value of attribute log.
23 24 25 |
# File 'lib/megalopolis/scheme.rb', line 23 def log @log end |
#novel ⇒ Object (readonly)
Returns the value of attribute novel.
21 22 23 |
# File 'lib/megalopolis/scheme.rb', line 21 def novel @novel end |
Instance Method Details
#comment(text, params = {}) ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/megalopolis/scheme.rb', line 50 def comment(text, params={}) get_params = param_serialize(params) uri = URI.parse(@base_url) Net::HTTP.start(uri.host, uri.port) do |http| header = { "User-Agent" => USER_AGENT } response = http.post(uri.path, get_param, header) end end |
#fetch_novel(base_url, log, id) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/megalopolis/scheme.rb', line 34 def fetch_novel(base_url, log, id) page = send_req(File.join(base_url, log.to_s, "#{id}.json")) novel = JSON.parse(page) novel["url"] = URI.join(base_url, "#{log}/#{id}").to_s return novel end |
#plain ⇒ Object
59 60 61 |
# File 'lib/megalopolis/scheme.rb', line 59 def plain return self.body.gsub(/(<br>|\r?\n|\s)/, "") end |
#simple_rating(point) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/megalopolis/scheme.rb', line 41 def (point) get_params = param_serialize({:point => point}) uri = URI.parse(@base_url) Net::HTTP.start(uri.host, uri.port) do |http| header = { "User-Agent" => USER_AGENT } response = http.post(uri.path, get_param, header) end end |