Sha256: 2a46c849d17002baf43d1b4d44ec9cac5991be60276049eee012b8601cd6ed4f

Contents?: true

Size: 795 Bytes

Versions: 37

Compression:

Stored size: 795 Bytes

Contents

#!/usr/bin/env ruby
# -*- encoding: utf-8 -*-
# Copyright muflax <mail@muflax.com>, 2013
# License: GNU GPL 3 <http://www.gnu.org/copyleft/gpl.html>

class File
  def self.save name, as: :text, &blk
    name = File.expand_path(name)

    # make sure directory exists
    dir = File.dirname(name)
    FileUtils.mkdir_p dir if not Dir.exists? dir

    # now open it
    case as
    when :anki
      f = CSV.open(name, "w", :col_sep => "\t", &blk)
    when :text
      f = File.open(name, "w", &blk)
    else
      raise "unsupported file format: #{as}"
    end

    f
  end

  def self.load name
    name = File.expand_path(name)

    file = case name
           when /\.gz$/
             Zlib::GzipReader.open(name)
           else
             File.open(name)
           end

    file
  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
muflax-0.5.1 lib/muflax/file.rb
muflax-0.5.0 lib/muflax/file.rb
muflax-0.4.2 lib/muflax/file.rb
muflax-0.4.1 lib/muflax/file.rb
muflax-0.4.0 lib/muflax/file.rb
muflax-0.3.23 lib/muflax/file.rb
muflax-0.3.22 lib/muflax/file.rb
muflax-0.3.21 lib/muflax/file.rb
muflax-0.3.20 lib/muflax/file.rb
muflax-0.3.19 lib/muflax/file.rb
muflax-0.3.18 lib/muflax/file.rb
muflax-0.3.17 lib/muflax/file.rb
muflax-0.3.16 lib/muflax/file.rb
muflax-0.3.14 lib/muflax/file.rb
muflax-0.3.13 lib/muflax/file.rb
muflax-0.3.12 lib/muflax/file.rb
muflax-0.3.11 lib/muflax/file.rb
muflax-0.3.10 lib/muflax/file.rb
muflax-0.3.9 lib/muflax/file.rb
muflax-0.3.8 lib/muflax/file.rb