Class: Xbrlware::Linkbase::CalculationLinkbase::Calculation
- Inherits:
-
Object
- Object
- Xbrlware::Linkbase::CalculationLinkbase::Calculation
- Defined in:
- lib/xbrlware-extras/linkbase.rb
Defined Under Namespace
Classes: CalculationArc
Instance Method Summary collapse
- #is_disclosure? ⇒ Boolean
- #leaf_items(period) ⇒ Object
- #print_tree(indent_count = 0, simplified = false) ⇒ Object
- #sort!(args) ⇒ Object
- #sprint_tree(indent_count = 0, simplified = false) ⇒ Object
- #top_level_arcs ⇒ Object
- #write_constructor(file, calc_name) ⇒ Object
Instance Method Details
#is_disclosure? ⇒ Boolean
27 28 29 30 31 32 |
# File 'lib/xbrlware-extras/linkbase.rb', line 27 def is_disclosure? return true if @title.downcase =~ /^disclosure/ return true if @title.downcase =~ /^summary of/ return true if @title.downcase =~ /details$/ return false end |
#leaf_items(period) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/xbrlware-extras/linkbase.rb', line 75 def leaf_items(period) #if @arcs.empty? if top_level_arcs.empty? raise RuntimeError.new("#{self.inspect} (#{@label}) has nil items!") if @items.nil? items = @items.select{ |x| !x.is_sub_leaf? } items.select!{ |x| x.context.period.to_pretty_s == period.to_pretty_s } if period return items end #return @arcs.collect { |child| child.leaf_items(period) }.flatten return top_level_arcs.collect { |child| child.leaf_items(period) }.flatten end |
#print_tree(indent_count = 0, simplified = false) ⇒ Object
71 72 73 |
# File 'lib/xbrlware-extras/linkbase.rb', line 71 def print_tree(indent_count=0, simplified=false) puts sprint_tree(indent_count, simplified) end |
#sort!(args) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/xbrlware-extras/linkbase.rb', line 45 def sort!(args) @arcs = @arcs.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.pretty_name}\" #{xscore <=> 0} \"#{y.pretty_name}\"" xscore <=> 0 end @arcs.each{ |arc| arc.sort!(args) } end |
#sprint_tree(indent_count = 0, simplified = false) ⇒ Object
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/xbrlware-extras/linkbase.rb', line 60 def sprint_tree(indent_count=0, simplified=false) indent = " " * indent_count output = indent + "Calc: #{@title} (#{@role})" + "\n" #@arcs.each { |arc| output += arc.sprint_tree(indent_count+1, simplified) } top_level_arcs.each { |arc| output += arc.sprint_tree(indent_count+1, simplified) } output += indent + "\n\n" output end |
#top_level_arcs ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/xbrlware-extras/linkbase.rb', line 34 def top_level_arcs uniq_arcs = [] @arcs.each do |arc| if @arcs.none?{ |other_arc| other_arc.contains_arc?(arc) } uniq_arcs.push arc end end return uniq_arcs end |
#write_constructor(file, calc_name) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/xbrlware-extras/linkbase.rb', line 14 def write_constructor(file, calc_name) file.puts "#{calc_name}_args = {}" file.puts "#{calc_name}_args[:title] = \"#{@title}\"" file.puts "#{calc_name}_args[:role] = \"#{@role}\"" file.puts "#{calc_name}_args[:arcs] = []" @arcs.each_with_index do |arc, index| arc_name = calc_name + "_arc#{index}" arc.write_constructor(file, arc_name) file.puts "#{calc_name}_args[:arcs].push #{arc_name}" end file.puts "#{calc_name} = Xbrlware::Factory.Calculation(#{calc_name}_args)" end |