Class: SimpleNexml
- Inherits:
-
Object
- Object
- SimpleNexml
- Defined in:
- lib/fishtank/simple_nexml.rb
Overview
Parse NeXML document and return some data
Instance Attribute Summary collapse
-
#doc ⇒ Object
Returns the value of attribute doc.
-
#entity ⇒ Object
Returns the value of attribute entity.
-
#taxon ⇒ Object
Returns the value of attribute taxon.
Instance Method Summary collapse
- #cells ⇒ Object
-
#initialize(doc: nil, taxon: nil, entity: nil) ⇒ SimpleNexml
constructor
A new instance of SimpleNexml.
- #otus ⇒ Object
-
#referenced_chars ⇒ Array
All chars referenced in rows.
-
#referenced_otus ⇒ Array
All chars referenced in rows.
-
#referenced_states ⇒ Array
All states referenced in rows.
- #rows ⇒ Object
- #stats ⇒ Object
Constructor Details
#initialize(doc: nil, taxon: nil, entity: nil) ⇒ SimpleNexml
Returns a new instance of SimpleNexml.
12 13 14 |
# File 'lib/fishtank/simple_nexml.rb', line 12 def initialize(doc: nil, taxon: nil, entity: nil) @doc = doc end |
Instance Attribute Details
#doc ⇒ Object
Returns the value of attribute doc.
8 9 10 |
# File 'lib/fishtank/simple_nexml.rb', line 8 def doc @doc end |
#entity ⇒ Object
Returns the value of attribute entity.
10 11 12 |
# File 'lib/fishtank/simple_nexml.rb', line 10 def entity @entity end |
#taxon ⇒ Object
Returns the value of attribute taxon.
9 10 11 |
# File 'lib/fishtank/simple_nexml.rb', line 9 def taxon @taxon end |
Instance Method Details
#cells ⇒ Object
30 31 32 |
# File 'lib/fishtank/simple_nexml.rb', line 30 def cells doc.css("cell") end |
#otus ⇒ Object
26 27 28 |
# File 'lib/fishtank/simple_nexml.rb', line 26 def otus doc.css("otus") end |
#referenced_chars ⇒ Array
Returns all chars referenced in rows.
40 41 42 |
# File 'lib/fishtank/simple_nexml.rb', line 40 def referenced_chars cells.inject({}) {|hsh, c| hsh.merge!(c.to_h['char'] => nil)}.keys end |
#referenced_otus ⇒ Array
Returns all chars referenced in rows.
52 53 54 |
# File 'lib/fishtank/simple_nexml.rb', line 52 def referenced_otus rows.css("row").inject({}) {|hsh, c| hsh.merge!(c.to_h['otu'] => nil)}.keys end |
#referenced_states ⇒ Array
Returns all states referenced in rows.
46 47 48 |
# File 'lib/fishtank/simple_nexml.rb', line 46 def referenced_states cells.inject({}) {|hsh, c| hsh.merge!(c.to_h['state'] => nil)}.keys end |
#rows ⇒ Object
34 35 36 |
# File 'lib/fishtank/simple_nexml.rb', line 34 def rows doc.css("row") end |
#stats ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/fishtank/simple_nexml.rb', line 16 def stats return { count: { otus: otus.count, rows: rows.count, cells: cells.count } } end |