Class: AozoraZip::Text
- Inherits:
 - 
      Object
      
        
- Object
 - AozoraZip::Text
 
 
- Defined in:
 - lib/aozora_zip/text.rb
 
Constant Summary collapse
- CREATED_DATE_PATTERN =
 Regexp.new("^([0-9A-Za-z]+)年([0-9A-Za-z]+)月([0-9A-Za-z]+)日作成\r\n".encode("cp932"))
- FOOTER_SEPARATOR_PATTERN =
 Regexp.new("\r\n\r\n底本:".encode("cp932"))
Instance Method Summary collapse
- #absolute_path ⇒ Object
 - #content ⇒ Object
 - #create_date_string(time) ⇒ Object
 - #find_created_date ⇒ Object
 - #footer_pos ⇒ Object
 - 
  
    
      #initialize(text_file, core)  ⇒ Text 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of Text.
 - #update(text) ⇒ Object
 - #update_created_date(time) ⇒ Object
 
Constructor Details
#initialize(text_file, core) ⇒ Text
Returns a new instance of Text.
      6 7 8 9  | 
    
      # File 'lib/aozora_zip/text.rb', line 6 def initialize(text_file, core) @text_file = text_file @core = core end  | 
  
Instance Method Details
#absolute_path ⇒ Object
      11 12 13  | 
    
      # File 'lib/aozora_zip/text.rb', line 11 def absolute_path File.join(@core.dirname, @text_file) end  | 
  
#content ⇒ Object
      15 16 17  | 
    
      # File 'lib/aozora_zip/text.rb', line 15 def content IO.binread(absolute_path).force_encoding("cp932") end  | 
  
#create_date_string(time) ⇒ Object
      32 33 34  | 
    
      # File 'lib/aozora_zip/text.rb', line 32 def create_date_string(time) "#{time.year}年#{time.month}月#{time.day}日作成" end  | 
  
#find_created_date ⇒ Object
      36 37 38 39 40 41  | 
    
      # File 'lib/aozora_zip/text.rb', line 36 def find_created_date m = CREATED_DATE_PATTERN.match(content, ) if m Time.new(m[1],m[2],m[3]) end end  | 
  
#footer_pos ⇒ Object
      23 24 25 26 27 28 29 30  | 
    
      # File 'lib/aozora_zip/text.rb', line 23 def m = FOOTER_SEPARATOR_PATTERN.match(content) if m m.pre_match.size + "\r\n\r\n".size else nil end end  | 
  
#update(text) ⇒ Object
      19 20 21  | 
    
      # File 'lib/aozora_zip/text.rb', line 19 def update(text) IO.binwrite(absolute_path, text) end  | 
  
#update_created_date(time) ⇒ Object
      43 44 45 46 47 48 49 50 51  | 
    
      # File 'lib/aozora_zip/text.rb', line 43 def update_created_date(time) m = CREATED_DATE_PATTERN.match(content, ) if m new_date = create_date_string(time).encode("cp932") m.pre_match + new_date + "\r\n" + m.post_match else nil end end  |