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

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

Defined Under Namespace

Classes: CalculationArc

Instance Method Summary collapse

Instance Method Details

#is_disclosure?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/xbrlware-extras/linkbase.rb', line 27

def is_disclosure?
  @title.downcase =~ /^disclosure/ ? true : false
end

#leaf_items(period) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/xbrlware-extras/linkbase.rb', line 51

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


42
43
44
45
46
47
48
49
# File 'lib/xbrlware-extras/linkbase.rb', line 42

def print_tree(indent_count=0)
  indent = " " * indent_count
  puts indent + "Calc: #{@title} (#{@role})"

  @arcs.each { |arc| arc.print_tree(indent_count+1) }

  puts indent + "\n\n"
end

#top_level_arcsObject



31
32
33
34
35
36
37
38
39
40
# File 'lib/xbrlware-extras/linkbase.rb', line 31

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