class GreenButtonClasses::GreenButtonEntry
Attributes
href[RW]
id[RW]
parent_href[RW]
published[RW]
title[RW]
updated[RW]
Public Class Methods
new(entry_xml, parent)
click to toggle source
# File lib/greenbutton/gb_classes.rb, line 19 def initialize(entry_xml, parent) if !entry_xml.nil? @entry_xml = entry_xml self.related_hrefs = [] self.other_related = [] pre_rule_assignment(parent) assign_rules find_related_entries end end
Public Instance Methods
additional_rules()
click to toggle source
# File lib/greenbutton/gb_classes.rb, line 34 def additional_rules [] end
assign_rules()
click to toggle source
# File lib/greenbutton/gb_classes.rb, line 46 def assign_rules (RULES + additional_rules).each do |rule| create_attr(rule.attr_name) rule_xml = @entry_xml.xpath(rule.xpath) value = rule_xml.empty? ? nil : rule_xml.text translated_value = value.nil? ? nil : Helper.translate(rule.type, value) self.send(rule.attr_name.to_s+"=", translated_value) end end
doc()
click to toggle source
# File lib/greenbutton/gb_classes.rb, line 38 def doc self.usage_point.doc end
find_by_href(href)
click to toggle source
# File lib/greenbutton/gb_classes.rb, line 42 def find_by_href(href) doc.xpath("//link[@rel='self' and @href='#{href}']/..")[0] end
pre_rule_assignment(parent)
click to toggle source
# File lib/greenbutton/gb_classes.rb, line 30 def pre_rule_assignment(parent) raise self.class + 'failed to implement pre_rule_assignment' end
Private Instance Methods
alt_link(href)
click to toggle source
# File lib/greenbutton/gb_classes.rb, line 103 def alt_link(href) # SDGE links map as .../MeterReading to .../MeterReading/\d+ regex = Regexp.new(href + '\/\d+$') related_link = doc.xpath("//link[@rel='self']").select do |e| if e['href'] =~ regex e.parent end end related_link[0] end
create_attr( name )
click to toggle source
# File lib/greenbutton/gb_classes.rb, line 118 def create_attr( name ) create_method( "#{name.to_s}=".to_sym ) { |val| instance_variable_set( "@" + name.to_s, val) } create_method( name.to_sym ) { instance_variable_get( "@" + name.to_s ) } end
create_method( name, &block )
click to toggle source
# File lib/greenbutton/gb_classes.rb, line 114 def create_method( name, &block ) self.class.send( :define_method, name, &block ) end