Class: Spark::Serializer::Text

Inherits:
Base
  • Object
show all
Defined in:
lib/spark/serializer/text.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#==, #batched?, #check_each, #error, #inspect, #load_from_file, #load_from_io, #name, #unbatch!

Constructor Details

#initialize(encoding = Encoding::UTF_8) ⇒ Text

Returns a new instance of Text.



7
8
9
10
11
# File 'lib/spark/serializer/text.rb', line 7

def initialize(encoding=Encoding::UTF_8)
  error('Encoding must be an instance of Encoding') unless encoding.is_a?(Encoding)

  @encoding = encoding
end

Instance Attribute Details

#encodingObject (readonly)

Returns the value of attribute encoding.



5
6
7
# File 'lib/spark/serializer/text.rb', line 5

def encoding
  @encoding
end

Instance Method Details

#load(data) ⇒ Object



13
14
15
# File 'lib/spark/serializer/text.rb', line 13

def load(data)
  data.to_s.force_encoding(@encoding)
end

#to_sObject



17
18
19
# File 'lib/spark/serializer/text.rb', line 17

def to_s
  "Text(#{@encoding})"
end