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
parse_related_entry(entry_xml) click to toggle source
# File lib/greenbutton/gb_classes.rb, line 76
def parse_related_entry(entry_xml)
  name = get_related_name(entry_xml)
  classParser = GreenButtonClasses.const_get(name)
  if !classParser.nil?
    self.add_related(Helper.underscore(name), classParser.new(entry_xml, self))
  else
    other_related.push(xml)
  end
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

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