Class: Xbrlware::Linkbase::CalculationLinkbase::Calculation::CalculationArc
- Inherits:
-
Object
- Object
- Xbrlware::Linkbase::CalculationLinkbase::Calculation::CalculationArc
- Defined in:
- lib/xbrlware-extras/linkbase.rb
Instance Method Summary collapse
- #contains_arc?(arc) ⇒ Boolean
- #leaf_items(period) ⇒ Object
- #print_tree(indent_count = 0, simplified = false) ⇒ Object
- #sort!(args) ⇒ Object
- #sprint_tree(indent_count = 0, simplified = false) ⇒ Object
- #write_constructor(file, arc_name) ⇒ Object
Instance Method Details
#contains_arc?(arc) ⇒ Boolean
127 128 129 130 131 132 133 134 135 136 |
# File 'lib/xbrlware-extras/linkbase.rb', line 127 def contains_arc?(arc) return false if @children.empty? @children.each do |child| return true if (child.label == arc.label) && (child.item_id == arc.item_id) return true if child.contains_arc?(arc) end return false end |
#leaf_items(period) ⇒ Object
181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/xbrlware-extras/linkbase.rb', line 181 def leaf_items(period) if @children.empty? raise RuntimeError.new("#{self} (#{@label}) has nil items!") if @items.nil? items = @items.select{ |x| !x.is_sub_leaf? } raise RuntimeError.new("#{self} (#{@label}) has a Hash for a period") if period and period.class==Hash items.select!{ |x| x.context.period.to_pretty_s == period.to_pretty_s } if period return items end return @children.collect { |child| child.leaf_items(period) }.flatten end |
#print_tree(indent_count = 0, simplified = false) ⇒ Object
177 178 179 |
# File 'lib/xbrlware-extras/linkbase.rb', line 177 def print_tree(indent_count=0, simplified=false) puts sprint_tree(indent_count, simplified) end |
#sort!(args) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/xbrlware-extras/linkbase.rb', line 110 def sort!(args) if @children @children = @children.sort do |x,y| xscore = 0 yitems = y.leaf_items(args[:period]) x.leaf_items(args[:period]).each do |xnode| yitems.each do |ynode| xscore = (xnode <=> ynode) # NOTE: Assumes caller has defined <=> for all leaf nodes end end puts "\"#{x.label}\" #{xscore <=> 0} \"#{y.label}\"" xscore <=> 0 end end (@children || []).each{ |child| child.sort!(args) } end |
#sprint_tree(indent_count = 0, simplified = false) ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/xbrlware-extras/linkbase.rb', line 138 def sprint_tree(indent_count=0, simplified=false) indent = " " * indent_count str = "#{indent} CA:#{@label}" if simplified (@items.last(1) || []).each do |item| str += " I:{#{item.pretty_name}} " # FIXME: First off, sub-leaf is terrible, non-standard, confusing terminology. Call it something else. # FIXME: Second, why aren't we calling Item::print_tree()? if item.is_sub_leaf? str += " [sub-leaf]" else str += " [non-sub-leaf]" end period = item.context.period period_str = period.is_duration? ? "#{period.value["start_date"]} to #{period.value["end_date"]}" : "#{period.value}" str += " [#{item.def["xbrli:balance"]}]" if item.def && item.def["xbrli:balance"] str += " (#{period_str}) = #{item.value}" if item.value end else (@items || []).each do |item| str += " I:{#{item.pretty_name}} " if item.is_sub_leaf? str += " [sub-leaf]" else str += " [non-sub-leaf]" end period = item.context.period period_str = period.is_duration? ? "#{period.value["start_date"]} to #{period.value["end_date"]}" : "#{period.value}" str += " [#{item.def["xbrli:balance"]}]" if item.def && item.def["xbrli:balance"] str += " (#{period_str}) = #{item.value}" if item.value end end output = indent + str + "\n" (@children || []).each { |child| output += child.sprint_tree(indent_count+1, simplified) } output end |
#write_constructor(file, arc_name) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/xbrlware-extras/linkbase.rb', line 91 def write_constructor(file, arc_name) file.puts "args = {}" file.puts "args[:item_id] = \"#{@item_id}\"" file.puts "args[:label] = \"#{@label}\"" file.puts "#{arc_name} = Xbrlware::Factory.CalculationArc(args)" file.puts "#{arc_name}.items = []" (@items || []).each_with_index do |item, index| item_name = arc_name + "_item#{index}" item.write_constructor(file, item_name) file.puts "#{arc_name}.items.push #{item_name}" end file.puts "#{arc_name}.children = []" (@children || []).each_with_index do |child, index| child_name = arc_name + "_child#{index}" child.write_constructor(file, child_name) file.puts "#{arc_name}.children.push #{child_name}" end end |