class AozoraZip::Text

Constants

CREATED_DATE_PATTERN

Public Class Methods

new(text_file, core) click to toggle source
# File lib/aozora_zip/text.rb, line 6
def initialize(text_file, core)
  @text_file = text_file
  @core = core
end

Public Instance Methods

absolute_path() click to toggle source
# File lib/aozora_zip/text.rb, line 11
def absolute_path
  File.join(@core.dirname, @text_file)
end
content() click to toggle source
# File lib/aozora_zip/text.rb, line 15
def content
  IO.binread(absolute_path).force_encoding("cp932")
end
create_date_string(time) click to toggle source
# File lib/aozora_zip/text.rb, line 32
def create_date_string(time)
  "#{time.year}年#{time.month}月#{time.day}日作成"
end
find_created_date() click to toggle source
# File lib/aozora_zip/text.rb, line 36
def find_created_date
  m = CREATED_DATE_PATTERN.match(content, footer_pos)
  if m
    Time.new(m[1],m[2],m[3])
  end
end
update(text) click to toggle source
# File lib/aozora_zip/text.rb, line 19
def update(text)
  IO.binwrite(absolute_path, text)
end
update_created_date(time) click to toggle source
# File lib/aozora_zip/text.rb, line 43
def update_created_date(time)
  m = CREATED_DATE_PATTERN.match(content, footer_pos)
  if m
    new_date = create_date_string(time).encode("cp932")
    m.pre_match + new_date + "\r\n" + m.post_match
  else
    nil
  end
end