Class: Swicky::JsonEncoder
- Inherits:
-
Object
- Object
- Swicky::JsonEncoder
- Defined in:
- lib/swicky/json_encoder.rb
Overview
Takes a number of triples and encodes them in the SIMILE JSON format
Instance Method Summary collapse
-
#initialize(triples) ⇒ JsonEncoder
constructor
A new instance of JsonEncoder.
- #to_json ⇒ Object
Constructor Details
#initialize(triples) ⇒ JsonEncoder
Returns a new instance of JsonEncoder.
6 7 8 9 10 11 12 |
# File 'lib/swicky/json_encoder.rb', line 6 def initialize(triples) @triples = triples @types_hash = {} @properties_hash = {} @label_hash = {} @label_inverse = {} end |
Instance Method Details
#to_json ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/swicky/json_encoder.rb', line 14 def to_json puts @triples.inspect @items ||= begin items = [] # First a round to make sure that each item has a label triple_hash.each { |object, values| values['label'] = make_label!(object, values) } # Now build the items themselves triple_hash.each { |object, values| items += build_item(object, values) } items end # hashy = { 'items' => @items, 'types' => @types_hash, 'properties' => @properties_hash } # puts hashy.inspect { 'items' => @items, 'types' => @types_hash, 'properties' => @properties_hash }.to_json end |