Class: SimpleNexml

Inherits:
Object
  • Object
show all
Defined in:
lib/fishtank/simple_nexml.rb

Overview

Parse NeXML document and return some data

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#docObject

Returns the value of attribute doc.



8
9
10
# File 'lib/fishtank/simple_nexml.rb', line 8

def doc
  @doc
end

#entityObject

Returns the value of attribute entity.



10
11
12
# File 'lib/fishtank/simple_nexml.rb', line 10

def entity
  @entity
end

#taxonObject

Returns the value of attribute taxon.



9
10
11
# File 'lib/fishtank/simple_nexml.rb', line 9

def taxon
  @taxon
end

Instance Method Details

#cellsObject



30
31
32
# File 'lib/fishtank/simple_nexml.rb', line 30

def cells
  doc.css("cell")
end

#otusObject



26
27
28
# File 'lib/fishtank/simple_nexml.rb', line 26

def otus
  doc.css("otus")
end

#referenced_charsArray

Returns all chars referenced in rows.

Returns:

  • (Array)

    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_otusArray

Returns all chars referenced in rows.

Returns:

  • (Array)

    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_statesArray

Returns all states referenced in rows.

Returns:

  • (Array)

    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

#rowsObject



34
35
36
# File 'lib/fishtank/simple_nexml.rb', line 34

def rows
  doc.css("row")
end

#statsObject



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