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



54
55
56
# File 'lib/novelinfo.rb', line 54

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
43
44
45
46
47
48
49
50
51
52
# 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 = "t-nt-ga-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["title"] = @setting["title"]
  novel_status = @setting["novel_type_string"][@setting["novel_type"]] || 1
  result["end"] = novel_status == 3
  result["novel_type"] = case novel_status
                         when 1, 3   # 連載
                           1
                         when 2      # 短編
                           ga = @setting["general_all_no"]
                           # ハーメルンで短編なのに連載形式のがあるため
                           ga && ga > "1" ? 1 : 2
                         end
  result["story"] = HTML.new(@setting["story"]).to_aozora
  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