Class: BioTable::RDF::Writer

Inherits:
Object
  • Object
show all
Defined in:
lib/bio-table/rdf.rb

Overview

Convenience class for writing RDF - tracks header values

Instance Method Summary collapse

Constructor Details

#initialize(use_blank_nodes) ⇒ Writer

Returns a new instance of Writer.



60
61
62
63
# File 'lib/bio-table/rdf.rb', line 60

def initialize use_blank_nodes
  @use_blank_nodes = use_blank_nodes
  @rownames = {}
end

Instance Method Details

#write(row, type) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/bio-table/rdf.rb', line 65

def write row, type
  if type == :header
    print RDF.namespaces
    @header = row.all_fields
    rdf = RDF.header(@header)
    print "# Table\n"
    print rdf.join("\n"),"\n\n"
  else
    if @rownames[row.rowname]
      if @use_blank_nodes
        logger = Bio::Log::LoggerPlus['bio-table']
        logger.warn "Duplicate row name <#{row.rowname}>"
      else
        raise "RDF expects unique row names! Duplicate <#{row.rowname}> found"
      end
    else
      @rownames[row.rowname] = true
    end
    rdf = RDF.row(row.all_fields,@header,@use_blank_nodes)
    print rdf,"\n"
  end
end