Class: NovelInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/novelinfo.rb

Constant Summary collapse

@@novel_info_parameters =
{}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(setting) ⇒ NovelInfo

Returns a new instance of NovelInfo.



18
19
20
21
22
# File 'lib/novelinfo.rb', line 18

def initialize(setting)
  @setting = setting
  @ncode = @setting["ncode"]
  @@novel_info_parameters[@setting["name"]] ||= {}
end

Class Method Details

.load(setting) ⇒ Object



13
14
15
16
# File 'lib/novelinfo.rb', line 13

def self.load(setting)
  info = new(setting)
  info.parse_novel_info
end

Instance Method Details

#date_string_to_time(date) ⇒ Object



44
45
46
# File 'lib/novelinfo.rb', line 44

def date_string_to_time(date)
  date ? Time.parse(date.sub(/[\((].+?[\))]/, "").tr("年月日時分秒", "///:::")) : nil
end

#parse_novel_infoObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/novelinfo.rb', line 24

def parse_novel_info
  info_url = @setting["novel_info_url"] or return nil
  result = @@novel_info_parameters[@setting["name"]][@ncode] ||= {}
  return result unless result.empty?
  of = "nt-s-gf-nu-gl-w"
  request_output_parameters = of.split("-")
  info_source = ""
  open(info_url) do |fp|
    info_source = Helper.pretreatment_source(fp.read, @setting["encoding"])
  end
  @setting.multi_match(info_source, *request_output_parameters)
  result["novel_type"] = @setting["novel_type_string"][@setting["novel_type"]] || 1
  result["story"] = @setting["story"]
  result["writer"] = @setting["writer"]
  %w(general_firstup novelupdated_at general_lastup).each do |elm|
    result[elm] = date_string_to_time(@setting[elm])
  end
  result
end