Class: Kimurai::Base::Saver
- Inherits:
-
Object
- Object
- Kimurai::Base::Saver
- Defined in:
- lib/kimurai/base/saver.rb
Instance Attribute Summary collapse
-
#append ⇒ Object
readonly
Returns the value of attribute append.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#position ⇒ Object
readonly
Returns the value of attribute position.
Instance Method Summary collapse
-
#initialize(path, format:, position: true, append: false) ⇒ Saver
constructor
A new instance of Saver.
- #save(item) ⇒ Object
Constructor Details
#initialize(path, format:, position: true, append: false) ⇒ Saver
Returns a new instance of Saver.
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/kimurai/base/saver.rb', line 9 def initialize(path, format:, position: true, append: false) unless %i(json pretty_json jsonlines csv).include?(format) raise "SimpleSaver: wrong type of format: #{format}" end @path = path @format = format @position = position @index = 0 @append = append @mutex = Mutex.new end |
Instance Attribute Details
#append ⇒ Object (readonly)
Returns the value of attribute append.
7 8 9 |
# File 'lib/kimurai/base/saver.rb', line 7 def append @append end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
7 8 9 |
# File 'lib/kimurai/base/saver.rb', line 7 def format @format end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
7 8 9 |
# File 'lib/kimurai/base/saver.rb', line 7 def path @path end |
#position ⇒ Object (readonly)
Returns the value of attribute position.
7 8 9 |
# File 'lib/kimurai/base/saver.rb', line 7 def position @position end |
Instance Method Details
#save(item) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/kimurai/base/saver.rb', line 22 def save(item) @mutex.synchronize do @index += 1 item[:position] = @index if position case format when :json save_to_json(item) when :pretty_json save_to_pretty_json(item) when :jsonlines save_to_jsonlines(item) when :csv save_to_csv(item) end end end |