Class: GreenButton::Parser

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(doc) ⇒ Parser

Returns a new instance of Parser.



26
27
28
29
30
31
32
# File 'lib/greenbutton.rb', line 26

def initialize(doc)
	@doc = doc
	@usage_points = []
	doc.xpath('//UsagePoint').each do |usage_point|
      @usage_points << UsagePoint.new(usage_point.parent.parent, self)
    end
end

Instance Attribute Details

#docObject

Returns the value of attribute doc.



24
25
26
# File 'lib/greenbutton.rb', line 24

def doc
  @doc
end

#usage_pointsObject

Returns the value of attribute usage_points.



24
25
26
# File 'lib/greenbutton.rb', line 24

def usage_points
  @usage_points
end

Instance Method Details

#filter_usage_points(params) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/greenbutton.rb', line 34

def filter_usage_points(params)
  # customer_id, service_kind, title, id, href
  filtered = []
  @usage_points.each do |usage_point|
    params.each_pair do |key, value|
      filtered << usage_point if usage_point.send(key) == value
    end
  end
  filtered
end

#get_unique(attr) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/greenbutton.rb', line 45

def get_unique(attr)
  #customer_id, service_kind, title
  unique = []
    @usage_points.each do |usage_point|
      val = usage_point.send(attr)
      if !unique.include?(val)
        unique << val
      end
    end
    unique
end