Class: Xbrlware::Item
- Inherits:
-
Object
- Object
- Xbrlware::Item
- Defined in:
- lib/xbrlware-extras/item.rb
Instance Method Summary collapse
- #is_sub_leaf? ⇒ Boolean
- #pretty_name ⇒ Object
- #print_tree(indent_count = 0) ⇒ Object
- #value(mapping = nil) ⇒ Object
- #write_constructor(file, item_name) ⇒ Object
Instance Method Details
#is_sub_leaf? ⇒ Boolean
61 62 63 |
# File 'lib/xbrlware-extras/item.rb', line 61 def is_sub_leaf? @context.entity.segment end |
#pretty_name ⇒ Object
25 26 27 |
# File 'lib/xbrlware-extras/item.rb', line 25 def pretty_name self.name.gsub(/([a-z])([A-Z])/, '\1 \2') end |
#print_tree(indent_count = 0) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/xbrlware-extras/item.rb', line 47 def print_tree(indent_count=0) 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"]}]" unless item.def.nil? output += " (#{period_str}) = #{item.value}" unless item.nil? end puts indent + output @children.each { |child| child.print_tree(indent_count+1) } end |
#value(mapping = nil) ⇒ Object
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/xbrlware-extras/item.rb', line 65 def value(mapping=nil) definition = case when @def.nil? then :unknown when @def["xbrli:balance"].nil? then :unknown else @def["xbrli:balance"].to_sym end mapping = mapping || ValueMapping.new return mapping.value(pretty_name, definition, @value.to_f) end |
#write_constructor(file, item_name) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/xbrlware-extras/item.rb', line 29 def write_constructor(file, item_name) item_context_name = item_name + "_context" if @context.nil? file.puts "#{item_context_name} = nil" else @context.write_constructor(file, item_context_name) end file.puts "#{item_name} = Xbrlware::Factory.Item(:name => \"#{@name}\"," + " :decimals => \"#{@decimals}\"," + " :context => #{item_context_name}," + " :value => \"#{@value}\")" if !@def.nil? and !@def["xbrli:balance"].nil? file.puts "#{item_name}.def = { } if #{item_name}.def.nil?" file.puts "#{item_name}.def[\"xbrli:balance\"] = \"#{@def['xbrli:balance']}\"" end end |