Class: GreenButton::Parser
- Inherits:
-
Object
- Object
- GreenButton::Parser
- Defined in:
- lib/greenbutton.rb
Instance Attribute Summary collapse
-
#doc ⇒ Object
Returns the value of attribute doc.
-
#usage_points ⇒ Object
Returns the value of attribute usage_points.
Instance Method Summary collapse
- #filter_usage_points(params) ⇒ Object
- #get_unique(attr) ⇒ Object
-
#initialize(doc) ⇒ Parser
constructor
A new instance of Parser.
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
#doc ⇒ Object
Returns the value of attribute doc.
24 25 26 |
# File 'lib/greenbutton.rb', line 24 def doc @doc end |
#usage_points ⇒ Object
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 |