Class: Spark::Serializer::Text
- Defined in:
- lib/spark/serializer/text.rb
Instance Attribute Summary collapse
-
#encoding ⇒ Object
readonly
Returns the value of attribute encoding.
Instance Method Summary collapse
-
#initialize(encoding = Encoding::UTF_8) ⇒ Text
constructor
A new instance of Text.
- #load(data) ⇒ Object
- #to_s ⇒ Object
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
#encoding ⇒ Object (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_s ⇒ Object
17 18 19 |
# File 'lib/spark/serializer/text.rb', line 17 def to_s "Text(#{@encoding})" end |