Class: Improvise::IO::DictionaryReader
- Inherits:
-
Object
- Object
- Improvise::IO::DictionaryReader
- Defined in:
- lib/improvise/io/dictionaryreader.rb
Instance Attribute Summary collapse
-
#format ⇒ Object
Returns the value of attribute format.
-
#gzip ⇒ Object
Returns the value of attribute gzip.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ DictionaryReader
constructor
A new instance of DictionaryReader.
- #read(io) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ DictionaryReader
Returns a new instance of DictionaryReader.
9 10 11 12 |
# File 'lib/improvise/io/dictionaryreader.rb', line 9 def initialize(opts={}) @format = opts[:format] || :marshal @gzip = opts[:gzip] || false end |
Instance Attribute Details
#format ⇒ Object
Returns the value of attribute format.
7 8 9 |
# File 'lib/improvise/io/dictionaryreader.rb', line 7 def format @format end |
#gzip ⇒ Object
Returns the value of attribute gzip.
7 8 9 |
# File 'lib/improvise/io/dictionaryreader.rb', line 7 def gzip @gzip end |
Class Method Details
.read(io, opts = {}) ⇒ Object
33 34 35 |
# File 'lib/improvise/io/dictionaryreader.rb', line 33 def self.read(io, opts={}) DictionaryReader.new(opts).read(io) end |
Instance Method Details
#read(io) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/improvise/io/dictionaryreader.rb', line 14 def read(io) input = nil if @gzip gz = Zlib::GzipReader.new(io) input = gz.read gz.close else input = io.read io.close end if @format == :json return JSON.load(input) else return Marshal.load(input) end end |