Class: GreenButtonClasses::GreenButtonEntry
- Inherits:
-
Object
- Object
- GreenButtonClasses::GreenButtonEntry
- Defined in:
- lib/greenbutton/gb_classes.rb
Direct Known Subclasses
ElectricPowerQualitySummary, ElectricPowerUsageSummary, IntervalBlock, LocalTimeParameters, MeterReading, ReadingType, UsagePoint
Instance Attribute Summary collapse
-
#href ⇒ Object
Returns the value of attribute href.
-
#id ⇒ Object
Returns the value of attribute id.
-
#other_related ⇒ Object
Returns the value of attribute other_related.
-
#parent_href ⇒ Object
Returns the value of attribute parent_href.
-
#published ⇒ Object
Returns the value of attribute published.
-
#related_hrefs ⇒ Object
Returns the value of attribute related_hrefs.
-
#title ⇒ Object
Returns the value of attribute title.
-
#updated ⇒ Object
Returns the value of attribute updated.
Instance Method Summary collapse
- #add_related(type, parser) ⇒ Object
- #additional_rules ⇒ Object
- #assign_rules ⇒ Object
- #doc ⇒ Object
- #find_by_href(href) ⇒ Object
- #find_related_entries ⇒ Object
-
#initialize(entry_xml, parent) ⇒ GreenButtonEntry
constructor
A new instance of GreenButtonEntry.
- #parse_related_entry(entry_xml) ⇒ Object
- #pre_rule_assignment(parent) ⇒ Object
Constructor Details
#initialize(entry_xml, parent) ⇒ GreenButtonEntry
Returns a new instance of GreenButtonEntry.
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/greenbutton/gb_classes.rb', line 19 def initialize(entry_xml, parent) if !entry_xml.nil? @entry_xml = entry_xml self. = [] self. = [] pre_rule_assignment(parent) assign_rules end end |
Instance Attribute Details
#href ⇒ Object
Returns the value of attribute href.
17 18 19 |
# File 'lib/greenbutton/gb_classes.rb', line 17 def href @href end |
#id ⇒ Object
Returns the value of attribute id.
17 18 19 |
# File 'lib/greenbutton/gb_classes.rb', line 17 def id @id end |
#other_related ⇒ Object
Returns the value of attribute other_related.
17 18 19 |
# File 'lib/greenbutton/gb_classes.rb', line 17 def @other_related end |
#parent_href ⇒ Object
Returns the value of attribute parent_href.
17 18 19 |
# File 'lib/greenbutton/gb_classes.rb', line 17 def parent_href @parent_href end |
#published ⇒ Object
Returns the value of attribute published.
17 18 19 |
# File 'lib/greenbutton/gb_classes.rb', line 17 def published @published end |
#related_hrefs ⇒ Object
Returns the value of attribute related_hrefs.
17 18 19 |
# File 'lib/greenbutton/gb_classes.rb', line 17 def @related_hrefs end |
#title ⇒ Object
Returns the value of attribute title.
17 18 19 |
# File 'lib/greenbutton/gb_classes.rb', line 17 def title @title end |
#updated ⇒ Object
Returns the value of attribute updated.
17 18 19 |
# File 'lib/greenbutton/gb_classes.rb', line 17 def updated @updated end |
Instance Method Details
#add_related(type, parser) ⇒ Object
86 87 88 |
# File 'lib/greenbutton/gb_classes.rb', line 86 def (type, parser) raise self.class + ' does not have any recognized relations.' end |
#additional_rules ⇒ Object
34 35 36 |
# File 'lib/greenbutton/gb_classes.rb', line 34 def additional_rules [] end |
#assign_rules ⇒ Object
46 47 48 49 50 51 52 53 54 |
# 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 ⇒ Object
38 39 40 |
# File 'lib/greenbutton/gb_classes.rb', line 38 def doc self.usage_point.doc end |
#find_by_href(href) ⇒ Object
42 43 44 |
# File 'lib/greenbutton/gb_classes.rb', line 42 def find_by_href(href) doc.xpath("//link[@rel='self' and @href='#{href}']/..")[0] end |
#find_related_entries ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/greenbutton/gb_classes.rb', line 56 def self. = [] @entry_xml.xpath("./link[@rel='related']/@href").each do |href| if /\/\d+$/i.match(href.text) = find_by_href(href.text) if () self. << href.text else warn 'no link found for href: ' + href.text end else doc.xpath("//link[@rel='up' and @href='#{href.text}']").each do |link| self. << link.attr('href') (link.parent) end end end end |
#parse_related_entry(entry_xml) ⇒ Object
76 77 78 79 80 81 82 83 84 |
# File 'lib/greenbutton/gb_classes.rb', line 76 def (entry_xml) name = (entry_xml) classParser = GreenButtonClasses.const_get(name) if !classParser.nil? self.(Helper.underscore(name), classParser.new(entry_xml, self)) else .push(xml) end end |
#pre_rule_assignment(parent) ⇒ Object
30 31 32 |
# File 'lib/greenbutton/gb_classes.rb', line 30 def pre_rule_assignment(parent) raise self.class + 'failed to implement pre_rule_assignment' end |