Class: JustInform::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/just_inform/parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeParser

Returns a new instance of Parser.



6
7
8
# File 'lib/just_inform/parser.rb', line 6

def initialize
  load
end

Instance Attribute Details

#docObject

Returns the value of attribute doc.



4
5
6
# File 'lib/just_inform/parser.rb', line 4

def doc
  @doc
end

Instance Method Details

#inspectObject



10
11
12
# File 'lib/just_inform/parser.rb', line 10

def inspect
  "#{self.class} - #{self.doc.children.first.name}"
end

#reports(doc = @doc) ⇒ Object



32
33
34
35
36
37
# File 'lib/just_inform/parser.rb', line 32

def reports(doc=@doc)
  reports = []
  
  doc.xpath('//InformationCollectionRequest').map {|r| reports << InformationCollectionRequest.new(r) }
  reports
end

#top(limit = 10, attrib_name = :burden_hours) ⇒ Object

Show top 10 forms, PRA.top(sort_by_symbol, number_of_results) parser.top(:burden,2) => [<Nokogiri::XML::Element>, <Nokogiri::XML::Element>]



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/just_inform/parser.rb', line 16

def top(limit=10, attrib_name=:burden_hours)
  @topx = []
  @topx_size = limit
  sort_method = attrib_name.to_sym
  
  reports.each_with_index do |report, index|
    if @topx.last
      add_report_to_topx(report.send(sort_method), index) if report.send(sort_method) > @topx.last[0]
    else
      @topx << [report.send(sort_method), reports[index]]
    end
  end
  
  @topx.map! {|x| [number_to_delimited(x[0]), x[1]]}
end