Class: CorrectHorseBatteryStaple::Writer::Json

Inherits:
File show all
Defined in:
lib/correct_horse_battery_staple/writer/json.rb

Instance Attribute Summary

Attributes inherited from File

#io

Attributes inherited from Base

#dest, #options

Instance Method Summary collapse

Methods inherited from File

#close

Methods inherited from Base

#close

Methods included from Common

#array_sample, #logger, #random_in_range, #random_number, #set_sample

Methods inherited from CorrectHorseBatteryStaple::Writer

make_writer, write

Constructor Details

#initialize(dest, options = {}) ⇒ Json

Returns a new instance of Json.



3
4
5
# File 'lib/correct_horse_battery_staple/writer/json.rb', line 3

def initialize(dest, options={})
  super
end

Instance Method Details

#write_corpus(corpus) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/correct_horse_battery_staple/writer/json.rb', line 7

def write_corpus(corpus)
  print '{"stats": '
  print corpus.stats.to_json
  print ', "corpus": ['
  i = 0
  corpus.each do |word|
    puts "," if i >= 1
    print(word.to_hash.to_json)
    i += 1
  end
  puts "]\n}"
end