Class: Logaling::Command::Renderers::TermJsonRenderer

Inherits:
TermRenderer
  • Object
show all
Defined in:
lib/logaling/command/renderers.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from TermRenderer

#glossary_name, #note, #source_term, #target_term

Constructor Details

#initialize(term, repository, config, options) ⇒ TermJsonRenderer

Returns a new instance of TermJsonRenderer.



138
139
140
141
142
# File 'lib/logaling/command/renderers.rb', line 138

def initialize(term, repository, config, options)
  super
  @index = 0
  @last_index = 0
end

Instance Attribute Details

#indexObject

Returns the value of attribute index.



136
137
138
# File 'lib/logaling/command/renderers.rb', line 136

def index
  @index
end

#last_indexObject

Returns the value of attribute last_index.



136
137
138
# File 'lib/logaling/command/renderers.rb', line 136

def last_index
  @last_index
end

Instance Method Details

#render(output) ⇒ Object



144
145
146
147
148
149
150
151
152
153
154
# File 'lib/logaling/command/renderers.rb', line 144

def render(output)
  first_line? ? output.puts("[") : output.puts(",")
  record = {
    :source => source_term, :target => target_term, :note => note,
    :source_language => @config.source_language,
    :target_language => @config.target_language,
    :glossary => glossary_name
  }
  output.print JSON.pretty_generate(record)
  output.puts("\n]") if last_line?
end