Class: Xbrlware::Linkbase::CalculationLinkbase::Calculation::CalculationArc

Inherits:
Object
  • Object
show all
Defined in:
lib/xbrlware-extras/linkbase.rb

Instance Method Summary collapse

Instance Method Details

#contains_arc?(arc) ⇒ Boolean

Returns:

  • (Boolean)


86
87
88
89
90
91
92
93
94
95
# File 'lib/xbrlware-extras/linkbase.rb', line 86

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



112
113
114
115
116
117
118
119
120
121
122
# File 'lib/xbrlware-extras/linkbase.rb', line 112

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


97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/xbrlware-extras/linkbase.rb', line 97

def print_tree(indent_count=0)
  indent = " " * indent_count
  output = "#{indent} #{@label}"

  (@items || []).each do |item|
    period = item.context.period
    period_str = period.is_duration? ? "#{period.value["start_date"]} to #{period.value["end_date"]}" : "#{period.value}"
    output += " [#{item.def["xbrli:balance"]}]" if item.def
    output += " (#{period_str}) = #{item.value}" if item.value
  end
  puts indent + output

  (@children || []).each { |child| child.print_tree(indent_count+1) }
end

#write_constructor(file, arc_name) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/xbrlware-extras/linkbase.rb', line 67

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