Class: Grom::Reader
- Inherits:
-
Object
- Object
- Grom::Reader
- Defined in:
- lib/grom/reader.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#edges_by_subject ⇒ Object
readonly
Returns the value of attribute edges_by_subject.
-
#objects ⇒ Object
readonly
Returns the value of attribute objects.
-
#statements_by_subject ⇒ Object
readonly
Returns the value of attribute statements_by_subject.
-
#subjects_by_type ⇒ Object
readonly
Returns the value of attribute subjects_by_type.
Instance Method Summary collapse
-
#initialize(data) ⇒ Reader
constructor
A new instance of Reader.
- #read_data ⇒ Object
Constructor Details
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
5 6 7 |
# File 'lib/grom/reader.rb', line 5 def data @data end |
#edges_by_subject ⇒ Object (readonly)
Returns the value of attribute edges_by_subject.
5 6 7 |
# File 'lib/grom/reader.rb', line 5 def edges_by_subject @edges_by_subject end |
#objects ⇒ Object (readonly)
Returns the value of attribute objects.
5 6 7 |
# File 'lib/grom/reader.rb', line 5 def objects @objects end |
#statements_by_subject ⇒ Object (readonly)
Returns the value of attribute statements_by_subject.
5 6 7 |
# File 'lib/grom/reader.rb', line 5 def statements_by_subject @statements_by_subject end |
#subjects_by_type ⇒ Object (readonly)
Returns the value of attribute subjects_by_type.
5 6 7 |
# File 'lib/grom/reader.rb', line 5 def subjects_by_type @subjects_by_type end |
Instance Method Details
#read_data ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/grom/reader.rb', line 15 def read_data # Reset all our hashes just in case @statements_by_subject = {} # TODO: Find a better name for this hash! @edges_by_subject = {} RDF::NTriples::Reader.new(@data) do |reader| reader.each_statement do |statement| subject = statement.subject.to_s # TODO: Use Ruby key value syntax in below method. Grom::Helper.lazy_array_insert(@statements_by_subject, subject, statement) predicate = statement.predicate.to_s if (statement.object =~ URI.regexp) == 0 && predicate != RDF.type.to_s predicate = Grom::Helper.get_id(predicate) @edges_by_subject[subject] ||= {} @edges_by_subject[subject][predicate] ||= [] @edges_by_subject[subject][predicate] << statement.object.to_s end end end self end |