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.



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

def initialize
  load
end

Instance Attribute Details

#docObject

Returns the value of attribute doc.



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

def doc
  @doc
end

Instance Method Details

#reports(doc = @doc) ⇒ Object



29
30
31
32
33
34
# File 'lib/just_inform/parser.rb', line 29

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>]



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/just_inform/parser.rb', line 13

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