Class: JsDuck::IO
- Inherits:
- 
      Object
      
        - Object
- JsDuck::IO
 
- Defined in:
- lib/jsduck/io.rb
Overview
A helper to use instead the builtin IO class to read files in correct encoding.
By default in Ruby 1.9 the encoding is auto-detected, which can have surprising results. So in here we read in all files in UTF-8 (the default) or in some other encoding specified through –encoding option and convert it to UTF-8 internally.
Constant Summary collapse
- @@encoding =
- "UTF-8"
Class Method Summary collapse
- 
  
    
      .encoding=(e)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Sets the external encoding to be used for reading files. 
- 
  
    
      .read(filename)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Reads given filename into string. 
Class Method Details
.encoding=(e) ⇒ Object
Sets the external encoding to be used for reading files. When it’s different from UTF-8, the input will be converted to UTF-8.
| 15 16 17 18 19 20 21 | # File 'lib/jsduck/io.rb', line 15 def self.encoding=(e) if e =~ /^UTF-8$/i @@encoding = e else @@encoding = e+":UTF-8" end end | 
.read(filename) ⇒ Object
Reads given filename into string
| 24 25 26 | # File 'lib/jsduck/io.rb', line 24 def self.read(filename) File.open(filename, "r:"+@@encoding) {|f| f.read } end |